I'm currently working on my map app using android studio. Everything's working perfectly except for the marker that I've added. I've been using the official documentation Google Maps Android API v2 as my guide but can't find my marker anywhere when I try to load the map. Am I missing something?
Here's my map activity:
import android.os.Bundle;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
import com.google.android.gms.maps.GoogleMap;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.CameraUpdateFactory;
public class MapFragment extends FragmentActivity implements OnMapReadyCallback
{
private SupportMapFragment sMapFragment;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
sMapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap mMap)
{
LatLng one = new LatLng(10.178, 122.560);
LatLng ILOILO = new LatLng(10.730278, 122.548889);
mMap.setBuildingsEnabled(true);
mMap.setMyLocationEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(ILOILO, 12));
mMap.addMarker(new MarkerOptions()
.title("Empty Lot 1")
.snippet("blah blah blah")
.position(one)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
}
}
And here's my map_layout:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
EDIT
I've also tried removing private SupportMapFragment sMapFragment;
and changing my
sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
sMapFragment.getMapAsync(this);
into
SupportMapFragment sMapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map));
sMapFragment.getMapAsync(this);
but I can't still find my marker.
As your Java code looks fine.. Try editing your XML files as per the Google Documentation for onMapReadyCallback listener
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
Hope this would Help!!