Reputation: 1
Here is the code which i wrote for Google Map project. But it is prompting error on the line no. 271 at getMapAsync().
private void setUpMap(double lat,double lon) {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync();
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon)));
mMap.animateCamera(CameraUpdateFactory.zoomTo(16.0f));
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
try {
new GetPlacesAsyncTask().execute(latLng.latitude, latLng.longitude);
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
}
}}
Upvotes: 0
Views: 802
Reputation: 156
You need to pass "new OnMapReadyCallback()" to getMapAsync() method like this :-
getMapAsync(new OnMapReadyCallback(){}):
Upvotes: 1