开发者

Forcing google to give "did you mean" options when using maps/localsearch API

开发者 https://www.devze.com 2022-12-28 01:03 出处:网络
I want m开发者_Go百科y application using Google local search and google maps to give my users the ability to choose from a number of locations when there are a number of possible answers to their quer

I want m开发者_Go百科y application using Google local search and google maps to give my users the ability to choose from a number of locations when there are a number of possible answers to their query. A good example would be "Overton, UK" - there are lots of places with this name in the country, and the google maps website gives several possible "did you mean results".

The API, however, doesn't give you this information. Both localsearch and GClientGeocoder return one result.

Is there a way to get the API to return a list of possible results?


Have you tried using geocode from google.maps.Geocoder() (version 3 of the Maps API)? I'm pretty sure that it returns an array of results:

    var geocoder = new google.maps.Geocoder();

    if(geocoder) {
        geocoder.geocode({address: address}, function(results, status) {
            if(status == google.maps.GeocoderStatus.OK) {
                //do stuff with results, which is an array of address results
            }

            else {
                //error handling
            }
        });
    }

    else {
        //error handling
    }

More information at Maps API V3 Services. The page goes into detail about the structure of the address results object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号