gpt4 book ai didi

android - 在 android 中使用 google direction api 进行 GPS 跟踪

转载 作者:行者123 更新时间:2023-11-29 21:54:11 25 4
gpt4 key购买 nike

在我的应用程序中设置驾驶路径然后启动 GPS 跟踪。移动位置颜色为红色。我正在使用谷歌地图方向 api。设置方向路径工作正常。但是 gps 跟踪不起作用。

如何启用 gps 和 gps 跟踪路径颜色?

这是我的代码:

public class MainActivity extends MapActivity implements LocationListener {

private static final String Location = null;
public MapView mapView ;
public List<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();
private LocationManager lm;
private LogOverlay logOverlay;
private GpsLog log;
double lat;
double lon;
public GeoPoint srcGeoPoint,destGeoPoint,interGeoPoint;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("*************1**************1");
setContentView(R.layout.activity_main);
System.out.println("*************2**************");
mapView = (MapView) findViewById(R.id.mapv);
mapView.setBuiltInZoomControls(true);
System.out.println("*************3**************");
lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 10,this);
double src_lat = 12.98472; // the testing source
double src_long = 80.17778;
double dest_lat = 13.00833; // the testing destination
double dest_long =80.2125;
double via_lat = 13.065; // the testing destination
double via_long = 80.2325;
srcGeoPoint = new GeoPoint((int) (src_lat * 1E6),
(int) (src_long * 1E6));
destGeoPoint = new GeoPoint((int) (dest_lat * 1E6),
(int) (dest_long * 1E6));

interGeoPoint = new GeoPoint((int) ( via_lat * 1E6),
(int) (via_long * 1E6));
mapView.getController().animateTo(srcGeoPoint);
mapView.getController().setZoom(15);
new LongOperation().execute("");
initMyLocation();
final MyLocationOverlay overlay = new MyLocationOverlay(this, mapView);
overlay.enableMyLocation();
overlay.enableCompass();
mapView.invalidate();
System.out.println("*************4**************");
}

private void initMyLocation() {
System.out.println("init my location *************");
// does not work in emulator
}

最佳答案

您好,请检查缺少的代码 fragment

// Adding current location on map view

private void addMyLocationOverlay() {
myLocation = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocation);

myLocation.enableMyLocation();

myLocation.runOnFirstFix(new Runnable() {
@Override
public void run() {
mapController.animateTo(myLocation.getMyLocation());
}
});

}

此代码将在 mapview 上显示当前位置动画蓝色白色闪烁点

无需使用位置管理器和调用 requestLocationUpdates

关于android - 在 android 中使用 google direction api 进行 GPS 跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13681340/

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