How to find all nearest intersection from a an address.

I need help with finding the longitude and latitude of all nearest intersections from an address using google API. Any help you could provide would be highly helpful. Thanks in advance.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Sandeep GuptaConnect With a Mentor ConsultantCommented:
String searchPattern = "123 Main St."
    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    //I use last known location, but here we can get real location
    Location lastKnownLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    List<Address> addresses = null;
    try {
        //trying to get all possible addresses by search pattern
        addresses = (new Geocoder(this)).getFromLocationName(searchPattern, Integer.MAX_VALUE);
    } catch (IOException e) {
    if (addresses == null || lastKnownLocation == null) {
        // location service unavailable or incorrect address

    Address closest = null;
    float closestDistance = Float.MAX_VALUE;
    // look for address, closest to our location
    for (Address adr : addresses) {
        if (closest == null) {
            closest = adr;
        } else {
            float[] result = new float[1];
            Location.distanceBetween(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), adr.getLatitude(), adr.getLongitude(), result);
            float distance = result[0];
            if (distance < closestDistance) {
                closest = adr;
                closestDistance = distance;
    return closest; //here can be null if we did not find any addresses by search
Sandeep GuptaConsultantCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.