Android getFromLocationName在边界框外返回结果

rai*_*ade 5 android android-mapview

我正在从我的Android应用程序进行位置搜索.用户输入一个地址,我使用以下代码进行查找,

 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){
        ;
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的边界框适用于澳大利亚,但如果我搜索"Los Angelos",它会在美国返回结果.有没有我错过的东西?在我看来,它应该只根据参考文档返回边界框内的地址

MKJ*_*ekh 5

从问题我尝试了这个,我得到的结果如下所示.

18.55, 72.54 = Mumbai
22.18, 70.56 = Rajkot
Run Code Online (Sandbox Code Playgroud)

1)

当我通过低纬度vaue向左下方搜索字符串时,我得到了这个

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) {
            ;
        }
Run Code Online (Sandbox Code Playgroud)

Logcat的这个

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
Run Code Online (Sandbox Code Playgroud)

2)

当我向左下方传递更高纬度的vaue并搜索字符串时,我得到了这个

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

Logcat的这个

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

3)

这里的doc 本身说:"在边界框内匹配的地址被赋予更高的等级." ,我认为他们的意思是说,如果搜索字符串是这个框之间的地址,则不必返回,如果他们找到了地址,即使它超出了边界框也会返回. 我假设; Bounding Box仅用于设置结果的优先级,而获取意味着从第一个框开始的结果,然后其他类似于get(0),get(1)的列表.但即使它们不在边界框中,也会给出结果.

4)

Geocoder.java这里,他们只是调用方法获取地址,传递double值作为参数simple..no任何检查结果都用于其他地方检查最低和最高值

=>所以最后回答你的问题,你只需要调用你正在调用的函数,你可以检查它们与你的匹配的第二个地址行意味着状态或国家是相同的.找到国家,你的边界框值的状态名称使用getFromLocation(纬度,经度,maxResults),我仍然没有找到一个完美的解决方案为此,所以我也搜索

=> 有关此问题的更多信息可由专家(我不是)或Google自己的开发人员解释.