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!
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!
[Google Maps Android API]
You can split the string by comma and then parse the string to long
To constructs a LatLng with the given latitude and longitude coordinates
[Google Maps JavaScript API]
To do same operation with Maps JavaScript API service (JSFiddle demo) -
Firstly you will want to split the string on the comma:
This will then give you two
String
variables, which you will want to parse as doubles like so because theLatLng
constructor takes two doubles for the latitude and longitude of the location:Finally, adding to the previous answer, you will then want to put these into a
LatLng
object which is the class frequently used by Google Maps: