Reputation: 46
So, I tried implementing my own version of the Google Maps Activity, but to no avail. I ran into a problem with my markers not showing up, after several hours of not figuring it out, I deleted my code and copied this guys working example. Except, when I run it, it's the same issue. The map won't zoom to a specified location nor will it display map markers. That makes me believe there is an issue with the onReady section, but I'm not sure. I've tried following other stack questions/answers but I can't seem to find out what's wrong. It displays the Google Map, which I can manually zoom around in and it updates the streets and whatnot, but no markers.
XML file:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.logintest.MapsActivity" />
Upvotes: 0
Views: 2616
Reputation: 46
Found the issue. It was actually a mistake in my other Java file. I was trying to switch acitivies, but instead of actually switching the activity, I only changed the view.
Upvotes: 0
Reputation: 128
Try by adding your markeroptions code in onMapReady() method. It might work as currently you are adding markers when there is change in location(onLocationChanged()).
LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);
Upvotes: 1