Google Maps API change view when options menu button was pressed?
Im trying to make the view change from traffic to satelite when a button in my options menu is pressed but its not working.. Here is my code: Here is my onCrete
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Adding features for the map
mainMap = (MapView)findViewById(R.id.mvMain);
mainMap.setBuiltInZoomControls(true);
//THESE I WILL USE!!!
//mainMap.setSatellite(true);
mainMap.setTraffic(true);
mapViewControll = true;
mapController = mainMap.getController();
}
here is my onoptionItemSelected
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemI开发者_运维知识库d()){
//Change View
case R.id.changeView:
if(mapViewControll = false){
mainMap.setSatellite(true);
}
else{
mainMap.setTraffic(true);
}
break;
//Help
case R.id.help:
break;
}
return super.onOptionsItemSelected(item);
}
I did set the mapViewControll boolean to true at the top of the code.. What can be a problem here??
Try calling invalidate() method on map view at end.
Forgot to put mainMap.setTraffic(false); and vice versa in the onoptionItemSelected method
精彩评论