Javascript 如何显示从地址到地址的方向
我得到了这个代码的纬度和经度值,在这里我想显示从地址到地址的方向,我不知道请帮助Javascript 如何显示从地址到地址的方向,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我得到了这个代码的纬度和经度值,在这里我想显示从地址到地址的方向,我不知道请帮助 window.onload=函数(){ 变量映射选项={ 中心:new google.maps.LatLng(12.9715987,77.594562699998),//来自地址纬度,经度值 缩放:14, mapTypeId:google.maps.mapTypeId.ROADMAP }; var infoWindow=new google.maps.infoWindow(); var latlngbounds
window.onload=函数(){
变量映射选项={
中心:new google.maps.LatLng(12.9715987,77.594562699998),//来自地址纬度,经度值
缩放:14,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var infoWindow=new google.maps.infoWindow();
var latlngbounds=new google.maps.latlngbounds();
var map=new google.maps.map(document.getElementById(“dvMap”)、mapOptions);
google.maps.event.addListener(映射,'click',函数(e){
警报(“纬度:+e.latLng.lat()+”\r\n长度:+e.latLng.lng());//我得到了地址纬度,经度值
});
}
您好,这个对您很有帮助,
方向服务的一个小例子,我使用的是“发件人地址”和“收件人地址”的中心点,只要你点击它,它就会把“收件人地址”带到其中。地图画出了驱动根
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Directions Travel Modes</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<input type="text" id="from_Latlng" value="12.9301397, 77.58773180000003" />
<input type="text" id="to_Latlng" value="" />
<script>
$(function(){ initialize(); });
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
var From = new google.maps.LatLng(12.9301397, 77.58773180000003);
var to_latLng=$("#to_Latlng").val();
if(to_latLng!='')
{
var to_LatLngSplit=to_latLng.split(",");
var to_lat=to_LatLngSplit[0];
var to_lng=to_LatLngSplit[1];
var to = new google.maps.LatLng(to_lat,to_lng);
}
else
{
var to = new google.maps.LatLng(12.9997841, 77.68394269999999);
}
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: From
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
// If there are any parameters at eh end of the URL, they will be in location.search
var lat,lng,zoom,type;
//looking something like "?marker=3"
directionsDisplay.setMap(map);
calcRoute(From,to);
google.maps.event.addListener(map, 'click', function (e) {
//alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());// i got TO address Latitude , Longitude value
$('#to_Latlng').val(e.latLng.lat()+","+e.latLng.lng());
initialize();
});
}
function calcRoute(From,to) {
var selectedMode = "DRIVING";
var request = {
origin: From,
destination: to,
travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Directions Request Failed, "+status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div>
<b>Mode of Travel: </b>
</div>
<div id="map_canvas" style="height: 450px;"></div>
</body>
</html>
谷歌地图JavaScript API v3示例:方向和旅行模式
$(函数(){initialize();});
方向显示;
var directionsService=new google.maps.directionsService();
var映射;
函数初始化(){
var From=new google.maps.LatLng(12.9301397,77.587731800003);
var to_latLng=$(“#to_latLng”).val();
如果(到拉丁语!='')
{
var to_LatLngSplit=to_latLng.split(“,”);
var to_lat=to_LatLngSplit[0];
var to_lng=to_LatLngSplit[1];
var to=new google.maps.LatLng(to_lat,to_lng);
}
其他的
{
var to=new google.maps.LatLng(12.999784177.683942699999);
}
directionsDisplay=new google.maps.DirectionsRenderer();
变量映射选项={
缩放:14,
mapTypeId:google.maps.mapTypeId.ROADMAP,
中心:从
}
map=new google.maps.map(document.getElementById('map_canvas'),mapOptions);
//如果URL末尾有任何参数,它们将位于location.search中
var lat、lng、缩放、类型;
//看起来像“?标记=3”
方向显示.setMap(地图);
卡尔克劳特(从,到);
google.maps.event.addListener(映射,'click',函数(e){
//警报(“纬度:+e.latLng.lat()+”\r\n长度:+e.latLng.lng());//我得到了地址纬度,经度值
$(“#to_Latlng').val(e.Latlng.lat()+”,“+e.Latlng.lng());
初始化();
});
}
函数计算器(从,到){
var selectedMode=“驾驶”;
var请求={
出处:从,,
目的地:至,
travelMode:google.maps.travelMode[selectedMode]
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}否则{
警报(“指示请求失败,”+状态);
}
});
}
旅行方式:
您好,这张对您很有帮助, 方向服务的一个小例子,我使用的是“发件人地址”和“收件人地址”的中心点,只要你点击它,它就会把“收件人地址”带到其中。地图画出了驱动根
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps JavaScript API v3 Example: Directions Travel Modes</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<input type="text" id="from_Latlng" value="12.9301397, 77.58773180000003" />
<input type="text" id="to_Latlng" value="" />
<script>
$(function(){ initialize(); });
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
var From = new google.maps.LatLng(12.9301397, 77.58773180000003);
var to_latLng=$("#to_Latlng").val();
if(to_latLng!='')
{
var to_LatLngSplit=to_latLng.split(",");
var to_lat=to_LatLngSplit[0];
var to_lng=to_LatLngSplit[1];
var to = new google.maps.LatLng(to_lat,to_lng);
}
else
{
var to = new google.maps.LatLng(12.9997841, 77.68394269999999);
}
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: From
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
// If there are any parameters at eh end of the URL, they will be in location.search
var lat,lng,zoom,type;
//looking something like "?marker=3"
directionsDisplay.setMap(map);
calcRoute(From,to);
google.maps.event.addListener(map, 'click', function (e) {
//alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());// i got TO address Latitude , Longitude value
$('#to_Latlng').val(e.latLng.lat()+","+e.latLng.lng());
initialize();
});
}
function calcRoute(From,to) {
var selectedMode = "DRIVING";
var request = {
origin: From,
destination: to,
travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
} else {
alert("Directions Request Failed, "+status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div>
<b>Mode of Travel: </b>
</div>
<div id="map_canvas" style="height: 450px;"></div>
</body>
</html>
谷歌地图JavaScript API v3示例:方向和旅行模式
$(函数(){initialize();});
方向显示;
var directionsService=new google.maps.directionsService();
var映射;
函数初始化(){
var From=new google.maps.LatLng(12.9301397,77.587731800003);
var to_latLng=$(“#to_latLng”).val();
如果(到拉丁语!='')
{
var to_LatLngSplit=to_latLng.split(“,”);
var to_lat=to_LatLngSplit[0];
var to_lng=to_LatLngSplit[1];
var to=new google.maps.LatLng(to_lat,to_lng);
}
其他的
{
var to=new google.maps.LatLng(12.999784177.683942699999);
}
directionsDisplay=new google.maps.DirectionsRenderer();
变量映射选项={
缩放:14,
mapTypeId:google.maps.mapTypeId.ROADMAP,
中心:从
}
map=new google.maps.map(document.getElementById('map_canvas'),mapOptions);
//如果URL末尾有任何参数,它们将位于location.search中
var lat、lng、缩放、类型;
//看起来像“?标记=3”
方向显示.setMap(地图);
卡尔克劳特(从,到);
google.maps.event.addListener(映射,'click',函数(e){
//警报(“纬度:+e.latLng.lat()+”\r\n长度:+e.latLng.lng());//我得到了地址纬度,经度值
$(“#to_Latlng').val(e.Latlng.lat()+”,“+e.Latlng.lng());
初始化();
});
}
函数计算器(从,到){
var selectedMode=“驾驶”;
var请求={
出处:从,,
目的地:至,
travelMode:google.maps.travelMode[selectedMode]
};
路由(请求、功能(响应、状态){