2012-09-25 99 views
0

我在顯示當前位置時遇到了問題。您能否告訴我如何添加可放大並顯示當前位置的代碼。在Android版Google API 10中顯示我的當前位置

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

你能告訴我的logcat錯誤消息 –

+0

好吧,讓我檢查再試一次 –

+0

嘗試使用LocationManager.GPS_PROVIDER而不是LocationManager.NETWORK_PROVIDER –

回答

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"/> 
+0

我嘗試這一點,但應用程序崩潰 –

+0

@ user1696683什麼錯誤,你得到? –

相關問題