2

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"

/>

yoshi24
  • 3,147
  • 8
  • 45
  • 62

2 Answers2

3

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.

craned
  • 2,991
  • 2
  • 34
  • 38
2

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.

barryku
  • 2,496
  • 25
  • 16
  • Thanks man that was awesome. just what i was looking for. Now, the only problem is when i do look for the location the screen is just a gray grid screen with google in the lower left corner. Ill post my xml up top – yoshi24 Jul 16 '11 at 02:50
  • that usually means that you don't have the right API key set up. – barryku Jul 16 '11 at 03:53
  • It works not but it is now giving my this 07-16 00:04:21.672: ERROR/MapActivity(2773): Couldn't get connection factory client I can see the map now though – yoshi24 Jul 16 '11 at 04:04
  • Take a look at http://stackoverflow.com/questions/6006835/android-mapactivity-couldnt-get-connection-factory-client. I just check my LogCat output, and am getting the same error which doesn't break any of my logic though. – barryku Jul 16 '11 at 05:26
  • Did that answer help you out? it didnt seem to fix the issue. Maybe i should just send maps a intent and forget about integrating maps into my app. its slowing me down and fustrating – yoshi24 Jul 16 '11 at 05:41
  • I have not try that solution since it doesn't cause any issue on my program. You might want to ignore that for now since it can be benign and should really be a warning not error. – barryku Jul 16 '11 at 06:18