OK so I'm working through a tutorial and my app is basically working except for one small detail. I have an Options menu to demonstrate things like showing the map as a Satellite view, zooming to specific places etc. etc.
The tutorial has two menu options as shown below which effectively need to be used in the order shown in order to zoom the map to where I'm currently located. I wanted to make the first item redundant (getcurrentlocation) by adding in the same functionality into the second menu item (showcurrentloaction) but this causes the app to crash.
Does anyone have any ideas why and how to overcome it. My thanks.
Cod snippet follows
case R.id.menu_getcurrentlocation:
// ---get your current location and display a blue dot---
map.setMyLocationEnabled(true);
break;
case R.id.menu_showcurrentlocation:
// Adding the next line breaks the app.
// map.setMyLocationEnabled(true);
Location myLocation = map.getMyLocation();
LatLng myLatLng = new LatLng(myLocation.getLatitude(),
myLocation.getLongitude());
CameraPosition myPosition = new CameraPosition.Builder()
.target(myLatLng).zoom(17).bearing(90).tilt(30).build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition));
break;
0 comments:
Post a Comment