I'm using Google Maps API v2 and I get a location coordinates single String "-34.8799074,174.7565664" from my SharedPreferences that I need to convert to LatLng.
Can anyone help with this please?
Thx!
On your computer, open Google Maps. Right-click the place or area on the map. This will open a pop-up window. You can find your latitude and longitude in decimal format at the top.
An immutable class representing a pair of latitude and longitude coordinates, stored as degrees.
[Google Maps Android API]
You can split the string by comma and then parse the string to long
String[] latlong = "-34.8799074,174.7565664".split(",");
double latitude = Double.parseDouble(latlong[0]);
double longitude = Double.parseDouble(latlong[1]);
To constructs a LatLng with the given latitude and longitude coordinates
LatLng location = new LatLng(latitude, longitude);
[Google Maps JavaScript API]
To do same operation with Maps JavaScript API service (JSFiddle demo) -
var latlong = '-34.397,150.644'.split(',');
var latitude = parseFloat(latlong[0]);
var longitude = parseFloat(latlong[1]);
var mapOptions = {
zoom: 8,
center: {lat: latitude, lng: longitude}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With