gpt4 book ai didi

java - 在 Android 版 Google API 10 中显示我的当前位置

转载 作者:行者123 更新时间:2023-12-01 15:08:53 25 4
gpt4 key购买 nike

我无法在此代码中显示我当前的位置。您能告诉我如何添加可缩放并显示我当前位置的代码吗?

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

最佳答案

对于您的 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"/>

关于java - 在 Android 版 Google API 10 中显示我的当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12580297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com