2011-07-11 26 views
1

私が本当に好きなGoogle Maps APIプレイス検索でこの例が見つかりました。 - Places Search私が追加したいのは、特定のLat/Lngの静的マーカーだけです。その結果、静的な場所から検索結果までの関係を見ることができます。私はマーカーを追加する方法を知っています...ちょうどこのコードではロードされていないようです。これがどのように行われるかについてのいかなる考えも非常に高く評価されるだろう。Googleプレイスに静的マーカーを追加する検索

答えて

0

私はあなたが欲しいものを確かめていませんが、directionsServiceを使うことができます。

グローバル変数:機能の初期化で

var directionDisplay; 
var directionsService = new google.maps.DirectionsService(); 
var startLocation; 
var markerStart; 

():

directionsDisplay = new google.maps.DirectionsRenderer(); 
directionsDisplay.setMap(map); 

google.maps.event.addListener(map, 'click', function(event) { 
    mapZoom = map.getZoom(); 
    startLocation = event.latLng; 
    setTimeout("placeMarkerStart()", 600); 
}); 

そして、もっとグローバルスタッフ:あなたはこれをテストしたい場合は

function placeMarkerStart() { 
    if(mapZoom == map.getZoom()){ 
     markerStart = new google.maps.Marker({ 
      position: startLocation, 
      map: map, 
      title: "start" 
     }); 
    } 
} 

function calcRoute(num) { 
    var request = { 
     origin: markerStart.getPosition(), 
     destination: markers[num].getPosition(), 
     travelMode: google.maps.TravelMode.DRIVING 
    }; 
    directionsService.route(request, function(result, status) { 
     if (status == google.maps.DirectionsStatus.OK) { 
      directionsDisplay.setDirections(result); 
     } 
    }); 
} 

はあなたが追加することができます。

<div id="locationField"> 
    ... 
    <input type="button" onclick="calcRoute(0);" id="start" value="0"/> 
    <input type="button" onclick="calcRoute(1);" id="start" value="1"/> 
    <input type="button" onclick="calcRoute(2);" id="start" value="2"/> 
</div> 

...と変更マップの位置:

#map_canvas { 
    position: absolute; 
    width: 399px; 
    height: 399px; 
    top: 55px; 
    left: 0px; 
    border: 1px solid grey; 
} 

これが唯一のアイデアだと完璧に動作しませんが、あなたがこれを好きなら、あなたはこれを再構築することができます。

関連する問題