Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find address by name of location (android google map)

Currently I am developing an android applicaiton. From my collection data, I have a list of location ( not address)- only name of location ( such as name of restaurant, resort, beach...), I want to find address of each location on Google Map API as the below image: enter image description here

How I can do it ?

I appreciate your help in this case. Thanks.

I'm also looking for a way to do it but I only find the solution to get Latitude or Longitude from specific address or in contrast.

I implemented as the below code but not result can be returned :(

    Geocoder coder = new Geocoder(this);
    List<Address> address;
    try {
    String locationName = "Nhà hàng Blanchy Street, VietNam";
    Geocoder gc = new Geocoder(this);
    List<Address> addressList = coder.getFromLocationName(locationName, 5);
    Address location = addressList.get(0);

    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

        LatLng sydney = new LatLng(latitude , longitude );
        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
like image 513
user2659694 Avatar asked Jul 17 '15 07:07

user2659694


People also ask

How do I find someone's address on Google Maps?

On your computer, open Google Maps and make sure you're signed in. Search for a contact's name or address. Matching contacts will appear in the suggestions. To see your contact on the map, choose a name or address.

Can you trace a path on Google Maps?

You can trace a path or highlight an area on your map by drawing lines and shapes.


1 Answers

There is a Geocoder class, which you can use to find the address by location name String. The method is

Geocoder gc = new Geocoder(context);
List<Address> addresses = gc.getFromLocationName(String locationName, int maxResults);

This will give you a list of Address objects. Address has methods getLongitude() and getLatitude(), among others.

And since your map is embedded, the GoogleMap class has a method moveCamera(...) to go the location, if any is found with your location name.

For example:

String locationName = "Nha Hang restaurant";
Geocoder gc = new Geocoder(context);
List<Address> addressList = gc.getFromLocationName(locationName, 5);

Then either use the Address or get the longitude and latitude to create CameraUpdate with CameraUpdateFactory. With this try the moveCamera(...) if you wish.

like image 190
milez Avatar answered Sep 29 '22 13:09

milez