Reputation: 1
I want to open google maps when I have address: when I have a state, city , street, number of building. I can only open a google maps when I have a lat and lon. How I can do this?
Upvotes: 1
Views: 749
Reputation: 1087
Here it's really simple to launch google maps from your application:
//geo:0,0 if you don't have lat/lng for the location and just wanna search using address.
Uri gmmIntentUri = Uri.parse("geo:0,0?q=pass the address here");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
//set package to "com.google.android.apps.maps" so that only google maps is opened.
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
Upvotes: 2
Reputation: 2057
You can get coordinates from adress by use Geocoder and after open google maps by coordinates
Something like that
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
Log.v("ddd", mAddress);
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
//To initialice list of address
List<Address> addresses = null;
try {
//To put the address in list
addresses = geocoder.getFromLocationName(mAddress, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Get Latitude and longitude
Address address = addresses.get(0);
mLongitude = address.getLongitude();
mlatitude = address.getLatitude();
Upvotes: 4