2013-09-23 49 views
-1

我試圖在樣式化地圖的中心添加標記(如下所示)。如何將標記添加到以下複雜樣式的地圖

(對不起,我只是無法獲得正確的語法)。


<!DOCTYPE html> 
<html> 
<head> 
<link href="css/default.css" rel="stylesheet"> 
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
<script> 

var map; 
var TDMP = new google.maps.LatLng(32.896187, -96.768493); 

function initialize() 

{var roadAtlasStyles = 
[ 
    { 
    featureType: 'road.highway', 
    elementType: 'geometry', 
    stylers: [ 
     { hue: '#355f7d' }, 
     { saturation: 60 }, 
     { lightness: -20 } 
     ] 
    }, 
    { 
    featureType: 'road.arterial', 
    elementType: 'all', 
    stylers: [ 
     { hue: '#c0dfdc' }, 
     { lightness: -40 }, 
     { saturation: 100 } 
     ] 
    }, 
    { 
    featureType: 'road.local', 
    elementType: 'all', 
    stylers: [ 
     { visibility: 'on' }, 
     { hue: '#f6ff00' }, 
     { saturation: 50 }, 
     { gamma: 0.7 }, 
     ] 
    } 
]; 

var mapOptions = { 
zoom: 14, 
center: TDMP, 
mapTypeControlOptions: { 
    mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'usroadatlas'] 
    } 
}; 

map = new google.maps.Map(document.getElementById('map-canvas'), 
mapOptions); 

var styledMapOptions = { 
name: 'US Road Atlas' 
}; 

var usRoadMapType = new google.maps.StyledMapType(
roadAtlasStyles, styledMapOptions); 

map.mapTypes.set('usroadatlas', usRoadMapType); 
map.setMapTypeId('usroadatlas'); 
} 


google.maps.event.addDomListener(window, 'load', initialize); 

</script> 

</head> 
<body> 
<div id="map-canvas"></div> 
</body> 
</html> 

我已經通過郵局讀取並添加例子下面的地圖,標記不會出現。

謝謝你的幫助。

+1

你有沒有看着[文件](https://developers.google.com/maps/documentation/javascript/overlays#Markers) ?將此代碼添加到您的代碼中(除了「位置」之外,直接從該示例中複製):var marker = new google.maps.Marker({ position:TDMP, map:map, title:「Hello World!」 });'爲我工作。 – geocodezip

回答

0

這使標記在地圖的中心:

<!DOCTYPE html> 
<html> 
<head> 
<link href="css/default.css" rel="stylesheet"> 
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
<script> 

var map; 
var TDMP = new google.maps.LatLng(32.896187, -96.768493); 

function initialize() 

{var roadAtlasStyles = 
[ 
    { 
    featureType: 'road.highway', 
    elementType: 'geometry', 
    stylers: [ 
     { hue: '#355f7d' }, 
     { saturation: 60 }, 
     { lightness: -20 } 
     ] 
    }, 
    { 
    featureType: 'road.arterial', 
    elementType: 'all', 
    stylers: [ 
     { hue: '#c0dfdc' }, 
     { lightness: -40 }, 
     { saturation: 100 } 
     ] 
    }, 
    { 
    featureType: 'road.local', 
    elementType: 'all', 
    stylers: [ 
     { visibility: 'on' }, 
     { hue: '#f6ff00' }, 
     { saturation: 50 }, 
     { gamma: 0.7 }, 
     ] 
    } 
]; 

var mapOptions = { 
zoom: 14, 
center: TDMP, 
mapTypeControlOptions: { 
    mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'usroadatlas'] 
    } 
}; 

map = new google.maps.Map(document.getElementById('map-canvas'), 
mapOptions); 

var styledMapOptions = { 
name: 'US Road Atlas' 
}; 

var marker = new google.maps.Marker({ 
    position: TDMP, 
    map: map, 
    title:"Hello World!" 
});` 

var usRoadMapType = new google.maps.StyledMapType(
roadAtlasStyles, styledMapOptions); 

map.mapTypes.set('usroadatlas', usRoadMapType); 
map.setMapTypeId('usroadatlas'); 
} 


google.maps.event.addDomListener(window, 'load', initialize); 

</script> 

</head> 
<body> 
<div id="map-canvas"></div> 
</body> 
</html> 
相關問題