2016-12-04 15 views
0

私はGoogle Mapsに検索クエリを渡す方法をお探しです。JS API。だから、私が見ることができるのは、検索ボックスをGoogleマップに組み込むことだ。私はユーザーがGoogleに入力する必要がないアプリケーションを開発しています。たとえば、私のリンク先ページにボストンの学校があります。ちょうどそれをクリックすると、ボストンの学校をハイライトすることができます。 このようなものSchools in Bostongoogle mapsに検索クエリを渡すJS api

ユーザーが検索ボックスに入力しなくても同じ機能を利用する方法が見つかりませんでした。 https://maps.googleapis.com/maps/api/js?callback=initMap&q=schools+in+bostonのようなAPIコールを期待していますが、何も見つかりませんでした。助けてください。

おかげで

+0

ここではAPIドキュメントです:https://developers.google.com/maps/documentation/javascript/places#はTextSearchRequestsとそれらが提供するコード: var request = { 場所:pyrmont、 半径: '500'、 クエリ: 'レストラン' }; サービス=新しいgoogle.maps.places.PlacesService(map); service.textSearch(request、callback); } –

答えて

3

ここではAPIドキュメントです:https://developers.google.com/maps/documentation/javascript/places#TextSearchRequestsとそれらが提供するコード:

var map; 
var service; 
var infowindow; 

function initialize() { 
    var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316); 

    map = new google.maps.Map(document.getElementById('map'), { 
     center: pyrmont, 
     zoom: 15 
    }); 

    var request = { 
    location: pyrmont, 
    radius: '500', 
    query: 'restaurant' 
    }; 

    service = new google.maps.places.PlacesService(map); 
    service.textSearch(request, callback); 
} 

function callback(results, status) { 
    if (status == google.maps.places.PlacesServiceStatus.OK) { 
    for (var i = 0; i < results.length; i++) { 
     var place = results[i]; 
     createMarker(results[i]); 
    } 
    } 
} 
関連する問題