Get Latitude and longitude of marker in google maps

给你一囗甜甜゛ 提交于 2019-11-28 06:38:17

Take a look at this function in your code.

   @Override
    public void onMarkerDragEnd(Marker marker) {
        // TODO Auto-generated method stub
        Toast.makeText(
                MainActivity.this,
                "Lat " + map.getMyLocation().getLatitude() + " "
                        + "Long " + map.getMyLocation().getLongitude(),
                Toast.LENGTH_LONG).show();
        System.out.println("yalla b2a "
                + map.getMyLocation().getLatitude());
    }

Here you are trying to get your current location on map which is wrong you should get location of marker that you dragged. You already have "marker" object here. Use that to get location of this draged marker's location.

LatLng position = marker.getPosition(); //
Toast.makeText(
                MainActivity.this,
                "Lat " + position.latitude + " "
                        + "Long " + position.longitude,
                Toast.LENGTH_LONG).show();
mEnE

It s quite simple i think if you want the long and lat coordinates with a long press ...

First, you have to do GoogleMap.setOnMapLongClickListener(this); and add to the signature of the containing class: implements OnMapLongClickListener

And here is the code:

@Override    
public void onMapLongClick(LatLng point) { 
    Toast.makeText(MainActivity.this, point.latitude+" "+point.longitude, Toast.LENGTH_SHORT).show();

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!