开发者

google Javascript API V3 places search with types=['geocode'] returns ZERO_RESULTS

I am having problem with Google places search. If I choose types: ['geocode'] i get no results (ZERO_RESULTS) regardless of a search term. What am i doing wrong? Here is my code snippet:

        ...
        var params = {
            name: searchTerm, //search Term is for example 'lon'
            bounds: map.getBounds(),
            types: ['geocode']
         }

        var service = new google.maps.places.PlacesService(map);
        service.search(params, function (results, status) {
                alert(status); - gives ZERO_RESULTS
         }
         ...

Update:

I want it to behave the same as Javascript AOI places Autocomplete. To get me the same results. I thought they are querying the same data?

var input = document.getElementById('location');
var options = {
    bounds: map.getBounds(),
    types: ['geocode']

};
autocomplete = new google.maps.开发者_开发问答places.Autocomplete(input, options);

google.maps.event.addListener(autocomplete, 'place_changed', function() {

.... This one gives me great results. ( reason i am not using autocomplete method over first solution is because i could not manage to auto select first item in autocomplete list once enter (in search fields) is hit. - if you know answer to that please help :)


At this time at least, it is best not to assume that Google Places has a lot of data for a location or that the data is finely categorized. It is entirely likely that Google Places has few or no places of type geocode for you to find.

Since types is optional, remove it and you will likely get results.

UPDATE: Regarding the Autocomplete vs. Places Search stuff that has been added to the question: I have not used Autocomplete, but I would think that it should not give you the same results. A Places Search is trying to find stuff that matches search term XXXXX. Autocomplete is trying to predict given substring XXXXXX what it is you may be trying to type. So it is likely to return more (and different, and in many cases less relevant) results. So what you are seeing (more results with Autocomplete) does not strike me as anomalous.


I have found that by removing the "types" parameter I get way more places. I am using places autocomplete and it definately gives me more options without the types.

I am just catching the enter key and stopping it, to prevent users submitting the form accidentally. Not quite what you wanted but it works for me.

        $("#LatLongSearch").keypress(function (event) {
            if (event.which == 13) {    // make enter key just search map and stop it from submitting form
                event.preventDefault();
            } 
        })


try this

$('#searchform').keypress(function(e) {
                if (e.which == 13) {
                e.preventDefault();
               google.maps.event.addListener(autocomplete, 'place_changed', function() {
                 fillInAddress();
                $('#yourform').submit();
        }); } });

It work for me

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜