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