在我的应用程序中,用户可以onLongClick将标记添加到Google地图。它将这些坐标保存为点。我知道,使用location = location.getLastKnownLocation可以使用方法getLongitude()和getLatitude()。无论如何,用户可以通过在Google地图上放置一个标记来执行此操作,以便可以检索坐标。这是获取标记点并将其存储的代码。

public void onMapLongClick(LatLng point) {
    tvLocInfo.setText("New marker added@" + point.toString());             map.addMarker(new MarkerOptions().position(point).title(point.toString()));
pointfinal = point;
Toast.makeText(this, point.toString(), Toast.LENGTH_LONG).show();
}

最佳答案

尝试这个:

public void onMapLongClick(LatLng point) {
    tvLocInfo.setText("New marker added@" + point.toString());
    //Create a marker object
    Marker myMarker = map.addMarker(new MarkerOptions().position(point).title(point.toString()));

    //And now you can use it's values
    myMarker.getPosition().latitude;
    myMarker.getPosition().longitude;
}


如果您有多个标记,则可以使用数组存储所有标记

09-10 07:17
查看更多