如何使用 Here Map for android SDK 获取经纬度?
How to get latitude and longitude using Here Map for android SDK?
我想在此处地图上的触摸位置添加标记。另外,我想显示我触摸位置的纬度和经度。
我成功显示了标记,但我无法在 toast 消息中显示纬度和经度。
我已经按照文档中的说明实现了自己的手势侦听器:
public class MyOnGestureListener implements MapGesture.OnGestureListener
在这里有一个我使用的覆盖方法:
@Override
public boolean onTapEvent(PointF p) {
// Toast.makeText(context, " Show latitude and langitude on touched location: " , Toast.LENGTH_SHORT ).show();
return true;
}
在这里我想显示纬度和经度。
您可以使用 Map#pixelToGeo(PointF point)
API 从 PointF
得到 GeoCoordinate
。然后你可以从 GeoCoordinate
.
中获取纬度和经度值
@AndrewJC 是对的。但对于初学者,我会解释一下。
这里SDK在其基本定位部分有如下实现
PositioningManager.OnPositionChangedListener
它提供了一个接口,onPositionUpdated
。从这里你可以得到 GeoPosition
。使用此 GeoPosition
获取纬度和经度。
double latitude = geoposition.getCoordinate().getLatitude();
double longitude = geoposition.getCoordinate().getLongitude();
With pixelToGeo(android.graphics.PointF point)
Geocoordinate geototap = map.pixelToGeo(pointf);
Double lat = geototap.getLatitude();
Double lng = geototap.getLongitude();
我想在此处地图上的触摸位置添加标记。另外,我想显示我触摸位置的纬度和经度。 我成功显示了标记,但我无法在 toast 消息中显示纬度和经度。
我已经按照文档中的说明实现了自己的手势侦听器:
public class MyOnGestureListener implements MapGesture.OnGestureListener
在这里有一个我使用的覆盖方法:
@Override
public boolean onTapEvent(PointF p) {
// Toast.makeText(context, " Show latitude and langitude on touched location: " , Toast.LENGTH_SHORT ).show();
return true;
}
在这里我想显示纬度和经度。
您可以使用 Map#pixelToGeo(PointF point)
API 从 PointF
得到 GeoCoordinate
。然后你可以从 GeoCoordinate
.
@AndrewJC 是对的。但对于初学者,我会解释一下。 这里SDK在其基本定位部分有如下实现
PositioningManager.OnPositionChangedListener
它提供了一个接口,onPositionUpdated
。从这里你可以得到 GeoPosition
。使用此 GeoPosition
获取纬度和经度。
double latitude = geoposition.getCoordinate().getLatitude();
double longitude = geoposition.getCoordinate().getLongitude();
With pixelToGeo(android.graphics.PointF point)
Geocoordinate geototap = map.pixelToGeo(pointf);
Double lat = geototap.getLatitude();
Double lng = geototap.getLongitude();