如何使用 HERE java sdk 获取坐标?
How can i get coordinates on tap using HERE java sdk?
我对 java 和 android 编程比较陌生,我想根据我在 HERE 地图上点击的点获取坐标。我真的希望你们能帮我解决这个问题。
编辑:
这是我尝试实现的代码,但是,它返回给我错误:
错误:(354, 53) 错误:找不到符号变量 PointF:
private void addDestination() {
image.setImageResource(R.drawable.marker);
GeoCoordinate endpoint = map.pixelToGeo(PointF);
MapMarker destination = new MapMarker(endpoint,image);
if (destination != null)
{
map.removeMapObject(destination);
}
else
{
map.addMapObject(destination);
}
}
PointF是数据类型,所以调用"map.pixelToGeo(PointF)"没有意义,需要用具体的数据来调用。
简而言之:
您需要监听点击事件(或长按,或您想要处理的任何事件),然后您将获得反映屏幕坐标的 PointF 数据。然后你可以通过 pixelToGeo 将屏幕坐标转换成地理坐标,你可以用它来添加地图标记或者你想在地图上用它做什么。
一些帮助您入门的代码:
监听地图上的点击事件(检索 PointF 屏幕坐标)是通过将 gestureListener 注册到您的地图视图来完成的。意思是,在成功完成 mapengine init 之后,你会做这样的事情:
yourMapViewInstance.getMapGesture().addOnGestureListener(yourGestureHandlerImpementation, 10, true);
并且在您的 gestureHandler 实现中,您可以覆盖多个事件(点击、长按等),例如您可以为长按执行以下操作:
private MapGesture.OnGestureListener yourGestureHandlerImpementation = new MapGesture.OnGestureListener.OnGestureListenerAdapter()
{
@Override
public boolean onLongPressEvent(PointF p) {
GeoCoordinate c = map.pixelToGeo(p);
// c is your geoccordinate on the map, where you clicked on the screen
// [...]
}
}
我对 java 和 android 编程比较陌生,我想根据我在 HERE 地图上点击的点获取坐标。我真的希望你们能帮我解决这个问题。
编辑:
这是我尝试实现的代码,但是,它返回给我错误:
错误:(354, 53) 错误:找不到符号变量 PointF:
private void addDestination() {
image.setImageResource(R.drawable.marker);
GeoCoordinate endpoint = map.pixelToGeo(PointF);
MapMarker destination = new MapMarker(endpoint,image);
if (destination != null)
{
map.removeMapObject(destination);
}
else
{
map.addMapObject(destination);
}
}
PointF是数据类型,所以调用"map.pixelToGeo(PointF)"没有意义,需要用具体的数据来调用。
简而言之: 您需要监听点击事件(或长按,或您想要处理的任何事件),然后您将获得反映屏幕坐标的 PointF 数据。然后你可以通过 pixelToGeo 将屏幕坐标转换成地理坐标,你可以用它来添加地图标记或者你想在地图上用它做什么。
一些帮助您入门的代码:
监听地图上的点击事件(检索 PointF 屏幕坐标)是通过将 gestureListener 注册到您的地图视图来完成的。意思是,在成功完成 mapengine init 之后,你会做这样的事情:
yourMapViewInstance.getMapGesture().addOnGestureListener(yourGestureHandlerImpementation, 10, true);
并且在您的 gestureHandler 实现中,您可以覆盖多个事件(点击、长按等),例如您可以为长按执行以下操作:
private MapGesture.OnGestureListener yourGestureHandlerImpementation = new MapGesture.OnGestureListener.OnGestureListenerAdapter()
{
@Override
public boolean onLongPressEvent(PointF p) {
GeoCoordinate c = map.pixelToGeo(p);
// c is your geoccordinate on the map, where you clicked on the screen
// [...]
}
}