0

I am getting lat/lng: (19.1972,72.93) in my String using

String position=String.valueOf(marker.getPosition());

how to get only latitude and longitude, I don't want to use split

Thanks in advance!

rookieDeveloper
  • 2,459
  • 1
  • 22
  • 44

3 Answers3

6

With marker.getPosition() you get a LatLng object which has a latitude and longitude properties.

So, you can do:

Double latitude = marker.getPosition().latitude;
Double longitude = marker.getPosition().longitude;

Hope it helps!

jos
  • 1,070
  • 12
  • 22
1

You can split Lat Long this way

String getLatLong="19.1972,72.93";
String[] str_split= getLatLong.split(","); // Split.
String getLat= str_split[0];
String getLong= str_split[1];

You should follow setOnMarkerClickListener

 your_map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
        {

            @Override
            public boolean onMarkerClick(Marker arg0) {
               // Creating a marker
            MarkerOptions markerOptions = new MarkerOptions();

            // Setting the position for the marker
            markerOptions.position(arg0); // get Latlong
            // Now you use above logic  
                return true;
            }

        });

Edit

use marker.getPosition().latitude; for better approach .

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
1

You can use (markerClick) instead of click with event. in ts file you can use event.latitude or event.longitude to get them }

Pran R.V
  • 1,015
  • 12
  • 21