我使用Google地圖JS API創建了我自己的樣式地圖。我想補充的方向功能,地圖,我跟着official tutorial(下顯示DirectionsResult冠軍),但最終的路線沒有出現......Google地圖API:路線結果不顯示
我調試我的代碼,我發現,比directionsService.route函數返回google.maps.DirectionsStatus.OK和directionsDisplay.setDirections(result)真的沒有JS錯誤調用...所以方向計算成功,但沒有顯示在我的地圖。 A試圖關閉特殊的地圖樣式,但即使在默認地圖樣式中也沒有出現。任何想法都可能是問題所在?
OK,一些代碼...:
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAB2gbXmG... ...mNs66iPr8&sensor=false&callback=directions_init"></script>
<script type="text/javascript">
var map;
var zoom = 11;
var directionsDisplay;
var directionsService;
function gmap_init(){
var styleArray = [ /*here is style but even if its commented its not working*/];
var alterMapStyle = new google.maps.StyledMapType(styleArray, {name: "ALTER style"});
var latlng = new google.maps.LatLng(/*lat, lng*/);
var myOptions = {
zoom: zoom,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
panControl: false,
zoomControl: false,
scaleControl: false,
streetViewControl: false
};
map = new google.maps.Map(document.getElementById("gmap"), myOptions);
map.mapTypes.set('ALTER_style', alterMapStyle);
map.setMapTypeId('ALTER_style');
}
function directions_init(){
directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer();
directionsDisplay.setMap(map);
display_route();
}
function display_route(){
var request = {
origin: 'Place A',
destination:'Place B',
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
//program got here without error
directionsDisplay.setDirections(result);
}
});
}
請發表一些代碼 – slawekwin 2012-02-16 10:12:08