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 に答える