2011-09-12 16 views
3

GoogleプレイスAPI(http://code.google.com/apis/maps/documentation/javascript/places.html)でプレイし始めたばかりですが、見えませんlatLngオブジェクトと半径ではなく、境界を渡す構文の権利を取得します。 APIドキュメントでGoogleプレイスAPIに境界を渡す

それは言う:

var bnds  = map.getBounds(); 
console.log(bnds); // this returns a valid bounds object! 
var req  = { 
       bounds: bnds 
       }; 
var service = new google.maps.places.PlacesService(map); 
service.search(req, callback); 

私はページを実行すると、私はGoogleのサービスからエラーUncaught Error: Property bounds not specifiedを取得:

This method takes a request with the following fields: Either of: bounds, which must be a google.maps.LatLngBounds object defining the rectangle in which to search; or a location and radius; the former takes a google.maps.LatLng object, and the radius takes a simple integer, representing the circle's radius in meters.

私のコードは次のようになります。 reqオブジェクトを

var req = { 
       location: latlngobject, 
       radius: '500' 
      } 

に変更すると、正しく動作します。 lat/lng/radiusではなくboundsオブジェクトを渡すための適切な構文に関する考え方はありますか?

+0

'var reqを送信するときに同じエラーが発生することを追加してください。 。 。場所:bnds' – julio

+0

「プロパティの場所が指定されていません」と表示されます。境界線を通過するときのみ。あなたはこれを解決しましたか? APIのバグであると思われます。 – Gady

答えて

-1

多分このコードスニペットは、あなた

VaRの限界=のmap.getBounds(役立ちます)。
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();

+0

これは、上記のPlaces APIの問題を実際に解決するものではありません。 – Gady

0

Google Places APIには、境界オプション/パラメータがありません。私はそれがここに少なくともどこでも言及されて表示されません:https://developers.google.com/places/documentation/

半径だけそうです。

+0

境界はオプションですhttps://developers.google.com/maps/documentation/javascript/places#TextSearchRequests –

+1

@Mike、あなたのリンクがGoogleプレイスAPI(ウェブサービス、HTTP)をポイントしています。マップApi場所ライブラリ(フロントエンド、Javascript)。バックエンドAPIにはboundsパラメータがありません。 –

1

を行うドキュメントは境界がオプションであることを示しています。

https://developers.google.com/maps/documentation/javascript/places#place_search_requests

Either of: bounds, which must be a google.maps.LatLngBounds object defining the rectangular search > area; or a location and radius; the form .....

私はこの問題を持っていたので、完全な誤りが示すように、私は他のパラメータを取り出し:

Uncaught Error: Property bounds is invalid (perhaps because of other properties).

rankByまたはキーワードまたはタイプのパラメータを取り出してから使用してください。

これらのパラメータは、私のために働く:あなたがそれを望むよう var arg = { bounds:map.getBounds(), types:['bar','airport'] };

がフルとしての種類を確認します。

境界がnearbySearch

0

次の例に比べてレーダー検索で私のために良い作品はGeocoder()結果から境界を取得し、それをあなたのPlacesService()結果を制限し、適切なデフォルトの場所マーカーを割り当てる方法を示します。

var geocoder = new google.maps.Geocoder(), 
    map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 10, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }), 
    rect = new google.maps.Rectangle({ 
     strokeColor: '#FF0000', 
     strokeOpacity: 0.3, 
     strokeWeight: 2, 
     fillColor: '#FF0000', 
     fillOpacity: 0.33, 
     map: map 
    }), 
    markers_amount = 10, 
    markers = []; 

// GEOCODE 
geocoder.geocode({ 
    'address': 'Vienna' 
}, function (results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
     var geometry = results[0].geometry, 
      places = new google.maps.places.PlacesService(map); 

     map.setCenter(bounds.getCenter()); 
     // SETS THE BOUNDS HERE 
     rect.setBounds(bounds); 

     places.search({ 
      bounds: bounds, 
      // https://developers.google.com/places/documentation/supported_types 
      types: [ 
       // Until there's enough meta data for Google, 
       // they label everything as an 'establishment'. 
       'establishment' 
      ] 
     }, function (results, status) { 
      if (status == google.maps.places.PlacesServiceStatus.OK) { 
       console.log(results); 
       for (var i = 0; i < markers_amount; i++) { 
        markers.push(new google.maps.Marker({ 
         position: results[i].geometry.location, 
         map: map, 
         icon: image = { 
          url: results[i].icon, 
          size: new google.maps.Size(71, 71), 
          origin: new google.maps.Point(0, 0), 
          anchor: new google.maps.Point(17, 34), 
          scaledSize: new google.maps.Size(25, 25) 
         } 
        })); 
       } 
      } 
     }); 
     //console.log(markers); 
    } else { 
     return $('#map').html('could not locate you'); 
    } 
}); 
関連する問題