我在显示此代码中的当前位置时遇到问题。你能否告诉我如何添加可以缩放和显示我当前位置的代码。
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);
答案 0 :(得分: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);
在Manifest文件中添加权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>