I'm making an app to search for addresses in Google Maps.
Is there any way to convert a String
to Location
, so I can get the longitude and latitude? Or is there a better way?
I'm making an app to search for addresses in Google Maps.
Is there any way to convert a String
to Location
, so I can get the longitude and latitude? Or is there a better way?
I found the answer (it took but found!).
Android has a class called Geocoder , which allows you to do these conversions. You must also give permission to access the internet and GPS:
uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"
Is it in JAVASCRIPT?
str = "12.12345 -15.12345"; x = str.split(" "); // para partir em 2 a string lat = x[0]; lon = x[1]; latLon = new google.maps.LatLng(lat, lon);
latLon will be in the format supported by the google app. Want a tip? see how the latLon format is written:
alert( JSON.stringify( latLon ) );