0

I am trying to display a particular place in maps for my android application, I was able to use longitude and latitude of this place to display it on map. However info bubble did not point to the place instead it pointed to the location based on longitude and latitude.

I want to display particular place in the given location.

Here's my code

double latitude = some value;
double longitude = some value;
String label = "Some text";
String loc = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String encodedQuery = Uri.encode(query);
String uriLoc = loc + "?q=" + encodedQuery + "&z=16";
Log.d(uriLoc, "no log");
Uri uri = Uri.parse(uriLoc);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
user3059993
  • 324
  • 1
  • 4
  • 9

3 Answers3

1

You should be able to do it using Geocoder: http://developer.android.com/reference/android/location/Geocoder.html

Kaifei
  • 1,568
  • 2
  • 13
  • 16
1

As suggested by user370305:

Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);

String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
Community
  • 1
  • 1
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
0

I was able to extract correct longitude and latitude values by using place name from getFromLocationName() method.

Code

Geocoder geocoder;
List<Address> addresses = null;
geocoder = new Geocoder(this, Locale.getDefault());
try {
//getFromLocationName returns array of address, it takes 2 parameter one place name and count of result
    addresses = geocoder.getFromLocationName("Place name", 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

latitude = addresses.get(0).getLatitude();
longitude = addresses.get(0).getLongitude();
String label = "SomePlace";
String in = "geo:" + latitude + "," + longitude;
String query = latitude + "," + longitude + "(" + label + ")";
String ey = Uri.encode(query);
String uriLoc = in + "?q=" + ey+ "&z=16";
Log.d(uriLoc, "no log");
Uri uri = Uri.parse(uriLoc);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, uri);
startActivity(intent);
user3059993
  • 324
  • 1
  • 4
  • 9