这里有以下代码,但是有错误。有人可以帮忙吗?
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);
}
答案 0 :(得分:6)
实际上,GeoPoint
以微度等级存储坐标,因此要将Location
转换为GeoPoint
,您将使用此代码:
GeoPoint point = new GeoPoint((int)(loc.getLatitude() * 1E6), (int)(loc.getLongitude() * 1E6));
希望这有帮助
答案 1 :(得分: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);
}
答案 2 :(得分:0)
GeoPoint pointRabat = new GeoPoint(microDegres(latitude),
microDegres(longitude));
mapController.setCenter(pointRabat);
private int microDegres(double value) {
return (int) (value * 1000000);
}