I´m designing an android app that locate places, these places are in a database in a server but I only have the name and location of the place, so I need to locate it in my app and put a marker there. It's posible to get coordinates only with address or, Do I need to redo my database adding fields with latitude and longitude?
How to get geographical coordinates in google maps API V2 android using an string address?
1.6k views Asked by Rene Limon At
3
There are 3 answers
0
On
You can make a request to google maps API to get possible addresses by a address string. Check this link.
0
On
You can use the Geocoder class, which will return the latitude and longitude for a given address in a specified format.However a specified format has to be followed for the address name. Check out for more information on this from the below link :- https://developer.android.com/reference/android/location/Geocoder
You can use the Geocoder class to do a look-up of the addresses you have, and then populate the map with Markers using the
LanLng
objects that are returned.Note that the
Geocoder
class will not be able to geocode every address, but it will be successful for most of them if they are in the correct format.Taking code from this question as a guide, I just got this simple example working.
I created a custom class that stores location name, location address, and a
LatLng
object to store the lat/lon.For this simple example, I just used three addresses.
Here is the full class code:
Result: