1
我正在做一個谷歌地圖項目,並需要創建一個點擊它的路線。谷歌地圖v3上可點擊的行車路線
我的項目有2個點,它有一個預定義的lat和lng,我想自己繪製A和B點的開始和結束,並且不會失去它的功能。
我做另外一個項目,你可以點擊繪製的路線,但它沒有標記,並且不draggabble,this is my actual project與完整的代碼 我會在這裏發表簡短的代碼只能用我的方向。
我想,我的第一次點擊的A點和第二點我B,並可能拖累他們,像項目鏈接
function goma()
{
var mapDiv = document.getElementById('mappy');
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(-23.563594, -46.654239),
mapTypeId : google.maps.MapTypeId.ROADMAP
}
pode ser ROADMAP, SATELLITE, HYBRID, TERRAIN
map = new google.maps.Map(mapDiv, mapOptions);
//Render route, etc.
ren = new google.maps.DirectionsRenderer({'draggable':true});
ren.setMap(map);
ren.setPanel(document.getElementById("directionsPanel"));
ser = new google.maps.DirectionsService();
//Create the route
ser.route({ 'origin': new google.maps.LatLng(-23.563594, -46.654129), 'destination': new google.maps.LatLng(
-23.563672, -46.640396), 'travelMode': google.maps.DirectionsTravelMode.DRIVING},function(res,sts) {
if(sts=='OK')ren.setDirections(res);
})
}
我更新這裏我的代碼,我做只有wayA,這是第一個路點,第二個是latLng預定義的,在那裏你點擊,它獲取latLng並放入'origin'中。
google.maps.event.addListener(map, "click", function(event) {
wayA = new google.maps.Marker({
position: event.latLng,
map: map
});
});
ren = new google.maps.DirectionsRenderer({'draggable':true});
ren.setMap(map);
ren.setPanel(document.getElementById("directionsPanel"));
ser = new google.maps.DirectionsService();
ser.route({ 'origin': wayA, 'destination': new google.maps.LatLng(
-23.563672, -46.640396), 'travelMode': google.maps.DirectionsTravelMode.DRIVING},function(res,sts) {
if(sts=='OK')ren.setDirections(res);
})
This is my test with the full code
感謝的人,我給你一起來投票的答案,我會盡量解決它,他們我在這裏評論,並檢查答案,另一個用戶看到=) – 2012-08-01 13:20:14
我更新了我的代碼和我嘗試 – 2012-08-01 14:44:48
更新我的回答用你的代碼的快速和骯髒的工作版本。 – geocodezip 2012-08-01 15:09:54