简体   繁体   English

在适用于Android的Google API 10中显示我当前的位置

[英]Show my current location in Google API 10 for Android

I'm having problem with showing my current location in this code. 在此代码中显示我的当前位置时遇到问题。 Can you please tell me how to add code that will zoom and show my current location. 您能告诉我如何添加可缩放并显示我当前位置的代码。

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);

For your GeoPoint you can use: 对于您的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));

And at the end add: 最后添加:

 mapView.getController().animateTo(point);

In the Manifest file add permission: 在清单文件中添加权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM