G.Maps 地理位置方向值。怎么做?
G.Maps Geolocation Directions Value. How Do?
然后我从 google 地图中获取此代码作为方向并开始工作,但我想将其作为 "start " 我的位置。地理定位的代码已经在里面了。
代码是这样的:
像这样
<style>
#map-canvas {
height: 400px;
}
</style>
<div id="map-canvas"></div>
<div id="panel">
<b>Start: </b>
<select id="start" onchange="updateRoute();">
<option value="My position (??)">My Position</option>
</select>
<b>End: </b>
<select id="end" onchange="updateRoute();">
<option value="Padova PD, It">Padova</option>
<option value="Milano">Parco</option>
</select>
</div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var mylocation = new google.maps.LatLng(45.4064349,11.876761100000067); // default location. When geolocation tracks the client, this variable is set to that location
function initialize() {
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.HYBRID
};
directionsDisplay = new google.maps.DirectionsRenderer();
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
map.setCenter(mylocation);
}
function updateRoute() {
calcRoute(mylocation);
}
function calcRoute(start) {
// var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
mylocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//document.getElementById('start').value = ;
if (map) {
calcRoute(position.coords.latitude +','+ position.coords.longitude);
}
})
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
然后我从 google 地图中获取此代码作为方向并开始工作,但我想将其作为 "start " 我的位置。地理定位的代码已经在里面了。 代码是这样的:
像这样
<style>
#map-canvas {
height: 400px;
}
</style>
<div id="map-canvas"></div>
<div id="panel">
<b>Start: </b>
<select id="start" onchange="updateRoute();">
<option value="My position (??)">My Position</option>
</select>
<b>End: </b>
<select id="end" onchange="updateRoute();">
<option value="Padova PD, It">Padova</option>
<option value="Milano">Parco</option>
</select>
</div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var mylocation = new google.maps.LatLng(45.4064349,11.876761100000067); // default location. When geolocation tracks the client, this variable is set to that location
function initialize() {
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.HYBRID
};
directionsDisplay = new google.maps.DirectionsRenderer();
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
map.setCenter(mylocation);
}
function updateRoute() {
calcRoute(mylocation);
}
function calcRoute(start) {
// var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
mylocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//document.getElementById('start').value = ;
if (map) {
calcRoute(position.coords.latitude +','+ position.coords.longitude);
}
})
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>