I am trying to pass the Latlng from MapsAutocomplete place activity to maps activity where i have the map view but when i try to pass lat lng to moveCamera method its showing null pointer exception but in my logs i am able to get the longitude and latitude can anyone help me with this problem. Thanks
The method where i pass the latlng to another activity:
private void NavigateToMaps(LatLng latLng){
Intent intent = new Intent(Maps2.this,Maps.class);
intent.putExtra("Location", latLng);
startActivity(intent);
Log.d(TAG, "NavigateToMaps: Clicked");
}
In my receiving activity where i need to show the address in the map pointer view:
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_view);
getLocationPermission();
LatLng locationAdd = getIntent().getExtras().getParcelable("Location");
Log.d(TAG, "onCreate: location" + locationAdd);
double latitude1 = locationAdd.latitude;
double longitude1 = locationAdd.longitude;
moveCamera(new LatLng(latitude1,longitude1),DEFAULT_ZOOM,"SelectedLocation");
}
private void moveCamera(LatLng latLng, float zoom,String tittle){
Log.d(TAG, "location: moving the camera to: lat: " + latLng.latitude + ", lng: " + latLng.longitude );
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
MarkerOptions options = new MarkerOptions()
.position(latLng)
.title(tittle);
mMap.addMarker(options);
}
In my log i am able to get latLng but null pointer is thrown:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.moveCamera(com.google.android.gms.maps.CameraUpdate)' on a null object reference at com.example.mappy.Maps.moveCamera(Maps.java:60)
2020-04-24 18:34:30.028 4051-4051/com.example.mappy D/Maps: onCreate: locationlat/lng: (13.007805,80.1273649) 2020-04-24 18:34:30.028 4051-4051/com.example.mappy D/Maps: location: moving the camera to: lat: 13.007805, lng: 80.1273649