Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getFromLocationName return results outside the bounding box

I am doing a location search from my android app. User enter an address and I do a lookup with the following code,

 private void doSearch(String query){
    FNMApplication.logInfo("Searching:"+query);
    //create a geocoder
    Geocoder gc = new Geocoder(this,Locale.getDefault());
    try{
        //lookup locations which match the query input by the user
        List<Address> addresses = gc.getFromLocationName(query, 5, -44.00, 111.00, -12.0, 155.0);
        //if there are any results save them in an ivar for re-use
        locationSearchResults=addresses;
        promptSearch();          
    }
    catch (Exception e){
        ;
    }
}

The bounding box above is for australia but if I search for "Los Angelos" it returns results in the US. Is there something I have missed? As I see it, it should only return addresses within the bounding box as per the reference document

like image 872
railwayparade Avatar asked Jun 27 '11 05:06

railwayparade


1 Answers

From the Question I tried this and the results I got are shown below.

18.55, 72.54 = Mumbai
22.18, 70.56 = Rajkot

1)

When I pass lower latitude vaue as left lower and search for the string I got this

Geocoder gc = new Geocoder(this, Locale.getDefault());
        try {

            List<Address> addresses = gc.getFromLocationName("akshardham", 5,
                    18.55, 72.54, 22.18, 70.56);

            Log.i("Address", "=========0----------------------"
                    + addresses.get(0).getAddressLine(0)
                    + addresses.get(0).getAddressLine(1));
            Log.i("Address", "=========0----------------------"
                    + addresses.get(1).getAddressLine(0)
                    + addresses.get(1).getAddressLine(1));
            Log.i("Address", "=========0----------------------"
                    + addresses.get(2).getAddressLine(0));
            Log.i("Address", "=========0----------------------"
                    + addresses.get(3).getAddressLine(0));
            Log.i("Address", "=========0----------------------"
                    + addresses.get(4).getAddressLine(0));
        } catch (Exception e) {
            ;
        }

Logcat of this

11-17 12:42:32.419: INFO/Address(802): =========0----------------------AkshardhamNH 8C, Sector 20
11-17 12:42:32.429: INFO/Address(802): =========0----------------------AkshardhamRajkot, Gujarat 360005
11-17 12:42:32.429: INFO/Address(802): =========0----------------------Akshardham

2)

When I pass higher latitude vaue as left lower and search for the string I got this

List<Address> addresses = gc.getFromLocationName("akshardham",5, 22.18, 70.56,18.55, 72.54 );

Logcat of this

11-17 12:43:53.170: INFO/Address(837): =========0----------------------HardhamPulborough, West Sussex RH20 1

3)

The doc here itself says "The addresses matching inside the bounding box is given higher rank." , I think they mean to say, Its not necessary that If search string is address between this box only will be return,if they found the address they will return even if its out of bounding box. I Suppose;Bounding Box is just for setting the priority of result while getting means result from the box wil be first and and then other like in get(0),get(1) of the list. but the result will be given even if they are not in bounding box.

4)

In the Geocoder.java here they are just calling the method to get addresses with passing double values as argument simple..no any checking for the result is used there else to check the lowest and highest value

=> So final answer to you problem you just call the function as you are calling and you can check the second address line that does they matches to yours means the state or country is same. to find the country,state name of your bounding box value use getFromLocation(latitude, longitude, maxResults), I still Didn't Find A Perfect Solution For this,So me too Searching

=> More on this can be explained by an expert (That's I am not) or Developer from Google itself.

like image 185
MKJParekh Avatar answered Oct 20 '22 13:10

MKJParekh