-1
我想使用地理定位來定位用戶的位置,然後在用戶的位置和固定點之間導航,但Google地圖不會導航,我正在使用Google官方文檔中的代碼!爲什麼谷歌地圖不能在我的網頁上導航?
怎麼了?我要去嘗試後數千次瘋狂,plz幫助
<script type="text/javascript">
$("#map-page").live("pageinit", function() {
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var salon = new google.maps.LatLng(22.981666,120.194301);
var defaultLatLng = new google.maps.LatLng(22.983587,120.22599); // Default to Hollywood, CA when no geolocation support
if (navigator.geolocation) {
function success(pos) {
// Location found, show map with these coordinates
drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
calcRoute(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
}
function fail(error) {
console.log(error);
drawMap(defaultLatLng); // Failed to find location, show default map
}
// Find the users current position. Cache the location for 5 minutes, timeout after 6 seconds
navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000});
} else {
drawMap(defaultLatLng); // No geolocation support, show default map
}
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
var marker = new google.maps.Marker({
position:new google.maps.LatLng(22.981666,120.194301),
map:map,
title:"the salon"
});
}
function calcRoute(latlng) {
var start = latlng;
var end = new google.maps.LatLng(22.981666,120.194301);
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);
}
});
}
});
</script>
你能給我寫一些代碼嗎?我是新來的Javascript – oratis 2012-08-09 03:44:08
但我設置directionsDisplay.setDirections(響應);這裏 – oratis 2012-08-09 04:33:56
@oratis:SO不會讓別人爲你寫代碼。還有其他網站,例如「Hire a Coder」:http://www.google.com/webhp?hl=zh-CN#hl=zh-CN&q=hire+a+coder&fp=1 – Marcelo 2012-08-09 06:59:58