Issue
What I am trying to do is display a Google Maps view when I click on a list item in my NavigationDrawer. The way I have it set up is that whenever I click on a list item, then the current fragment is replaced with a new one.
So, when I click on "Find Stores" list item, my StoreMapFragment replaces the current fragment.
The problem I am having is that the Google logo and zoom-in and zoom-out buttons appear on the bottom of the screen, but the actual map itself will not show.
I have looked at many of the guides for the Google Maps Android API v2 and similar issues & questions asked on StackOverflow. I have also tried doing this using an activity, but I get the same results.
At first, I didn't see any errors in the stack trace. Now this is what it says:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fv4.app"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<permission
android:name="com.fv4.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.fv4.app.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Teatimefinal">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAxwMnDDx7pP23x3sB8ZqACsXC3MUDfE7c" />
</application>
</manifest>
StoreMapFragment.java
public class StoreMapFragment extends Fragment implements OnMapReadyCallback {
MapView mapView;
GoogleMap googleMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_store_map, container, false);
mapView = (MapView) view.findViewById(R.id.store_map_frag);
mapView.onCreate(savedInstanceState);
if (mapView != null) {
googleMap = mapView.getMap();
googleMap.getUiSettings().setMyLocationButtonEnabled(false);
// googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setZoomControlsEnabled(true);
}
return view;
}
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(0, 0))
.title("Marker"));
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView
android:id="@+id/store_map_frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
And this is what my screen looks like:
Solution
OK. I figured out the problem. The issue was with the SHA-1 fingerprint. I realized that I was using the wrong SHA-1. I actually used the example SHA-1 from Google Maps Android API. So, I decided to look on StackOverflow on how to get my own SHA-1, here: How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?
And now I can see the map.
Answered By - freddiev4
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.