Android-从GeoPoint对象获取坐标

Android-从GeoPoint对象获取坐标,android,coordinates,mylocationoverlay,Android,Coordinates,Mylocationoverlay,看看这个: MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView); myLocationOverlay.enableMyLocation(); myLocationOverlay.enableCompass(); GeoPoint myGeoPoint = myLocationOverlay.getMyLocation(); 那很好。但是我需要把坐标保存在一个变量中。所以

看看这个:

MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, mapView);


    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
    GeoPoint myGeoPoint = myLocationOverlay.getMyLocation();
那很好。但是我需要把坐标保存在一个变量中。所以我试了一下:

myLocationLon = (double) myGeoPoint.getLongitudeE6();

当我运行应用程序时,最后一行使它崩溃。你能告诉我为什么这样不行吗?谢谢

地球点。getLongitudeE6()
地球点。GetLatitude6()
都返回微度(基本上是度*1E6)

因此,您需要将微度转换为度,只需编写函数:

public double microDegreesToDegrees(int microDegrees) {
    return microDegrees / 1E6;
}
然后

myLocationLon = microDegreesToDegrees(myGeoPoint.getLongitudeE6());

Thx,但这似乎不起作用。当我尝试启动应用程序时,最后一行导致崩溃。发布日志肯定会有助于解决问题。我认为问题是,当我调用你的函数时,经度值还不存在。这里有一个屏幕:myLocationLon=(myGeoPoint.getLongitudeE6()/1E6)//不起作用