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.
OffshorentAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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
        return;
    }

    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
0
 
Sandeep GuptaConsultantCommented:
0
All Courses

From novice to tech pro — start learning today.