請幫助我,我該如何在當前位置設置標記? 下面我的代碼onCreate,addMarker和createMapView。標記在我的位置?
的onCreate 公共類MapActivity延伸活動{
GoogleMap googleMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_activity);
createMapView();
addMarker();
}
addMarker
private void addMarker() {
if (null != googleMap) {
googleMap.addMarker(new MarkerOptions()
.title("Marker")
.position(new LatLng(0, 0))
.draggable(true));
}
}
createMapView
private void createMapView() {
try {
if (null == googleMap) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapView)).getMap();
if (null == googleMap) {
Toast.makeText(getApplicationContext(), "Error creating map", Toast.LENGTH_LONG).show();
}
}
} catch (NullPointerException e) {
Log.e("mapApp", e.toString());
}
}
你所示的代碼,有什麼問題? –
我如何設置當前位置? – user3729037