Reputation: 3177
I have been doing alot of research and no articles yet to tell you how to actually show a location of an actual address. If any one knows a good tutorial that shows this please let me know. Also feel free to leave a tutorial here. Thanks
To be more specific i would like to take an address and locate it on the map. I know i will have to use geocoding. But i dont want just the lat and lon. the actual location
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/>
Upvotes: 2
Views: 3701
Reputation: 3051
This question is asking for help using the map api, but if that's not essential to your app, I got it working without the help of the map api, and it seems to work quite nicely. Once you have your address, which does not have to include the city, state, and/or zip if you don't have them, use the following:
Uri uri = Uri.parse("https://www.google.com/maps/place/" + streetAddress);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
address example: "[street], [city], [state] [zip]"
Just the Internet permission in the AndroidManifest
is required.
This will give the user a list of apps available to display the given address, which when chosen, displays the location of the given address. Somebody is welcome to correct me if I'm wrong, but if a city, state, and/or zip are not provided, Google Maps at least, will find the closest physical address to the user's location matching what it was given if the address itself is not unique.
Upvotes: 3
Reputation: 2584
Take a look at GeoCoder.getFromLocationName(name, maxResult). The name can be either a location name or an actual address. Your code will be something like the following,
itemizedOverlay.addOverlay(getOverlayByAddress("1600 Amphitheatre Parkway, Mountain View, CA 94043", "Google"));
private OverlayItem getOverlayByAddress(String address, String name) throws IOException {
Geocoder geo = new Geocoder(this);
List<Address> addresses = geo.getFromLocationName(address, 5);
OverlayItem overlay = new OverlayItem(
new GeoPoint((int) (addresses.get(0).getLatitude() * 1E6),(int)(addresses.get(0).getLongitude()*1E6)),
name, "");
return overlay;
}
Note that it may fail on emulator with "Service not Available." If you encounter the error, just try it on a real device. Take a look at http://www.anddev.org/simple_googlemaps_geocoder_-_convert_address_to_lon-lat-t2936.html if you need more instructions.
Upvotes: 2