我试图让应用程序在谷歌地图上显示我的位置,但在我的手机上打开应用程序时它总是打开同一个地方,这是我在代码中添加的值作为测试的初始值编译器。我怎样才能让它显示我的位置(让它根据我的位置改变纬度和经度)?
这是代码:
公共类 AndroidGoogleMapsActivity 扩展 MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Displaying Zooming controls
MapView mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
/**
* Changing Map Type
* */
mapView.setSatellite(true); // Satellite View
// mapView.setStreetView(true); // Street View
mapView.setTraffic(true); // Traffic view
/**
* showing location by Latitude and Longitude
* */
MapController mc = mapView.getController();
double lat = Double.parseDouble("31.894178");
double lon = Double.parseDouble("35.872694");
GeoPoint geoPoint = new GeoPoint((int)(lat * 1E6), (int)(lon * 1E6));
mc.animateTo(geoPoint);
mc.setZoom(15);
mapView.invalidate();
/**
* Placing Marker
* */
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
AddItemizedOverlay itemizedOverlay =
new AddItemizedOverlay(drawable, this);
OverlayItem overlayitem = new OverlayItem(geoPoint, "Hello", "Sample Overlay item");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}