开发者

Google Maps Javascript API V3 : Search Requests

开发者 https://www.devze.com 2023-03-10 19:12 出处:网络
When calling search service api var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316); var request = { location: pyrmont, radius: \'500\', types: [\'store\'] };

When calling search service api

var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
var request = { location: pyrmont, radius: '500', types: ['store'] };
service = new google.maps.places.PlacesService(map);
service.search(request, callback);
  1. is it necessary to give the location/radius of the search area?
  2. What about if i want to search a location in total world not in specified area like google does at http://maps.google.com/.

--- UPDATE ---

This is my updated code as @Trott advised but i am getting status = "ZERO_RESULTS" in my callback function.

var keyword='search placename';
var request = { name : keyword,
bounds : new google.maps.LatLngBounds(
google.maps.LatLng(-89.999999,-179.999999),
google.maps.LatLng(8开发者_StackOverflow9.999999,179.999999)
)};
service = new google.maps.places.PlacesService(map);
service.search(request, callback);

function callback(results, status)
{
    console.log("status="+status);
    if ( status == google.maps.places.PlacesServiceStatus.OK)
    {
        for (var i = 0; i < results.length; i++)
        console.log(results[i]); 
    }
}

What i am doing wrong?


  1. Calls to search() must contain either a location and a radius, or else a bounds (as a LatLngBounds object). This is documented at http://code.google.com/apis/maps/documentation/javascript/places.html#place_search_requests.

  2. You could see what happens if you specify a LatLngBnds that covers the entire world. Haven't tried it, but if it worked, that should have the effect of searching the whole world without necessarily biasing a particular location.

LatLngBounds is documented at http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds. I think you'd want to do something like this:

var sw = new google.maps.LatLng(-89.999999,-179.999999);
var ne = new google.maps.LatLng(89.999999,179.999999);
var bounds = new google.maps.LatLngBounds(sw,ne);
0

精彩评论

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