-1

我有以下代码,但有错误。有人可以帮忙吗?

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

    }
4

3 回答 3

6

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

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

希望这可以帮助

于 2012-07-25T10:32:32.597 回答
1

我正在使用以下方法创建具有度数和/或微度数的 GeoPoints:

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

}
于 2012-07-25T10:32:57.353 回答
0
GeoPoint pointRabat = new GeoPoint(microDegres(latitude),
                microDegres(longitude));
        mapController.setCenter(pointRabat);


    private int microDegres(double value) {
        return (int) (value * 1000000);
    }
于 2012-07-25T10:40:56.160 回答