0

我在这段代码中显示我的当前位置时遇到问题。你能告诉我如何添加可以缩放并显示我当前位置的代码吗?

public class MapaActivity extends MapActivity
{

 @Override
 public void onCreate(Bundle savedInstanceState)
 {

 super.onCreate(savedInstanceState);
 setContentView(R.layout.mapa);

 MapView mapView = (MapView) findViewById(R.id.mapview);
 mapView.setBuiltInZoomControls(true);

 List<Overlay> mapOverlays = mapView.getOverlays();
 Drawable drawable = this.getResources().getDrawable(R.drawable.icon);
 HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);

 GeoPoint point = new GeoPoint(44900101,14839100);
 OverlayItem overlayitem = new OverlayItem(point, "Pin","Test pin");

 itemizedoverlay.addOverlay(overlayitem);



 mapOverlays.add(itemizedoverlay);
4

1 回答 1

1

对于您的 GeoPoint,您可以使用:

LocationManager locationManager;
        locationManager=(LocationManager) getSystemService(LOCATION_SERVICE);
        Location location=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        GeoPoint point=new GeoPoint((int)(location.getLatitude()*1E6),(int)(location.getLongitude()*1E6));

最后添加:

 mapView.getController().animateTo(point);

在清单文件中添加权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
于 2012-09-25T10:22:08.400 回答