Skip to content

Commit

Permalink
Added function to reverse geocode a search string into an address; ad…
Browse files Browse the repository at this point in the history
…ded logging.
  • Loading branch information
colabug committed Jul 26, 2011
1 parent bab6072 commit a95700b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/com/greenlife/parking/ParkingMap.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.greenlife.parking;

import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.os.Bundle;

import com.google.android.maps.*;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

public class ParkingMap extends MapActivity
{
// Constants
private static final String TAG = ParkingMap.class.getSimpleName();
private static final int PHILADELPHIA_LATITIUDE = 39952222;
private static final int PHILADELPHIA_LONGITUDE = -75164166;
private static final int CAR_LATITIUDE = 39945017;
Expand Down Expand Up @@ -54,6 +60,40 @@ public void onCreate( Bundle savedInstanceState )
mapOverlays = mapView.getOverlays();
createAlertOverlays();
createCarOverlays();

// Search for and navigate to a searched for point on the map
String searchString = "Fairmount Park, Philadelphia, PA";
GeoPoint point = getLocationForAddress( searchString );

if ( point != null )
{
Log.d( TAG, "point = " + point );
mapController.animateTo( point );
mapView.invalidate();
}
}

private GeoPoint getLocationForAddress( String searchString )
{
Log.d( TAG, "Searching for: " + searchString );
Geocoder geoCoder = new Geocoder( this, Locale.getDefault() );
try
{
List<Address> addresses;
addresses = geoCoder.getFromLocationName( searchString, 5 );

if ( addresses.size() > 0 )
{
return new GeoPoint((int) ( addresses.get( 0 ).getLatitude() * 1E6 ),
(int) ( addresses.get( 0 ).getLongitude() * 1E6 ) );
}
}
catch ( IOException exception)
{
exception.printStackTrace();
}

return null;
}

private void createAlertOverlays()
Expand Down

0 comments on commit a95700b

Please sign in to comment.