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