Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓-获取lon和lat的当前位置并放入一个地质点?_Android - Fatal编程技术网

Android 安卓-获取lon和lat的当前位置并放入一个地质点?

Android 安卓-获取lon和lat的当前位置并放入一个地质点?,android,Android,这里有以下代码,但有错误。有人能帮忙吗 实际上,GeoPoint以微度存储坐标,因此要将位置转换为GeoPoint,您将使用以下代码: GeoPoint point = new GeoPoint((int)(loc.getLatitude() * 1E6), (int)(loc.getLongitude() * 1E6)); 希望这有助于我使用以下方法创建具有度和/或微度的地质点: /** * Create a {@link GeoPoint} from float values. * @

这里有以下代码,但有错误。有人能帮忙吗


实际上,
GeoPoint
以微度存储坐标,因此要将
位置
转换为
GeoPoint
,您将使用以下代码:

GeoPoint point = new GeoPoint((int)(loc.getLatitude() * 1E6), (int)(loc.getLongitude() * 1E6));

希望这有助于

我使用以下方法创建具有度和/或微度的地质点:

/**
 * Create a {@link GeoPoint} from float values.
 * @param lat Latitude as float
 * @param lng Longitude as float
 * @return {@link GeoPoint}
 */
public static GeoPoint createGeoPoint( double lat, double lng) {
        return new GeoPoint(degreesToMicrodegrees(lat), degreesToMicrodegrees(lng));
}

/** Convert a float point degree value into a micro deree value */
public static int degreesToMicrodegrees( double deg ) {
        return (int)(deg * 1E6);
}
这应该对你有帮助

因此,您的代码如下所示:

public void onLocationChanged(Location loc) {
    // TODO Auto-generated method stub
    GeoPoint point = createGeoPoint(loc.getLatitude(),loc.getLongitude());
    OverlayItem overlayitem = new OverlayItem(point, "My Current Location", "My Current Location");
    overlay.addOverlay(overlayitem);
    mapOverlays.add(overlay);

}

@jeet GeoPoint需要整数,但loc.getLatitude()返回一个double,因为它是手写的:D
public void onLocationChanged(Location loc) {
    // TODO Auto-generated method stub
    GeoPoint point = createGeoPoint(loc.getLatitude(),loc.getLongitude());
    OverlayItem overlayitem = new OverlayItem(point, "My Current Location", "My Current Location");
    overlay.addOverlay(overlayitem);
    mapOverlays.add(overlay);

}
GeoPoint pointRabat = new GeoPoint(microDegres(latitude),
                microDegres(longitude));
        mapController.setCenter(pointRabat);


    private int microDegres(double value) {
        return (int) (value * 1000000);
    }