2014-12-05 136 views
-2

我是新編程Google地圖。我一直努力讓自己的地圖使用自定義圖像塊(出魔獸世界的)和我一直在這裏下列指南:http://facepunch.com/showthread.php?t=1184658無法將標記添加到自定義瓷磚地圖

Ive得到的地圖顯示,一切都那樣的工作。但現在我試圖添加標記,他們不會出現,任何人都可以幫忙嗎?

繼承人我的代碼:(沒有在那裏的標誌代碼)。

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
<style type="text/css"> 
     html { height: 100% } 
     body { height: 100%; margin: 0px; padding: 0px } 
     #map_canvas { height: 100%; z-index: 0;} 
     #gmnoprint {width: auto;} 
</style> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
<title>Google Map of the WoW World</title> 
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
<script> 
function CustomMapType() { 
} 
CustomMapType.prototype.tileSize = new google.maps.Size(256,256); 
CustomMapType.prototype.maxZoom = 7; 
CustomMapType.prototype.getTile = function(coord, zoom, ownerDocument) { 
    var div = ownerDocument.createElement('DIV'); 
    var baseURL = 'http://d1m6g5gl70bc4l.cloudfront.net/'; 
    baseURL += zoom + '_' + coord.x + '_' + coord.y + '.png'; 
    div.style.width = this.tileSize.width + 'px'; 
    div.style.height = this.tileSize.height + 'px'; 
    div.style.backgroundColor = '#1B2D33'; 
    div.style.backgroundImage = 'url(' + baseURL + ')'; 
    return div; 
}; 

CustomMapType.prototype.name = "Custom"; 
CustomMapType.prototype.alt = "Tile Coordinate Map Type"; 
var map; 
var CustomMapType = new CustomMapType(); 
function initialize() { 
    var mapOptions = { 
     minZoom: 2, 
    maxZoom: 7, 
    isPng: true, 
     mapTypeControl: false, 
     streetViewControl: false, 
     center: new google.maps.LatLng(0,0),  
     zoom: 3, 
    mapTypeControlOptions: { 
     mapTypeIds: ['custom', google.maps.MapTypeId.ROADMAP], 
     style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 
    } 

    }; 
map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions); 
map.mapTypes.set('custom',CustomMapType); 
map.setMapTypeId('custom'); 
} 
</script> 
</head> 
<body onload="initialize()"> 
<div id="map_canvas" style="background: #1B2D33;"></div> 
</body> 
</html> 
+1

請提供一個[最小,完整,已測試和可讀的示例](http://stackoverflow.com/help/mcve),它演示了您所問的問題。沒有任何你的標記碼,你的可能不會顯示標記(顯然)。你做了什麼來添加不起作用的標記? [添加標記](https://developers.google.com/maps/documentation/javascript/markers#add)(來自文檔) – geocodezip 2014-12-05 01:38:30

回答

0

documentation on adding Markers, 到標記添加到地圖中,使用 '地圖' 屬性

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

code code snippet:

function initialize() { 
 
    var mapOptions = { 
 
    minZoom: 2, 
 
    maxZoom: 7, 
 
    isPng: true, 
 
    mapTypeControl: false, 
 
    streetViewControl: false, 
 
    center: new google.maps.LatLng(0, 0), 
 
    zoom: 3, 
 
    mapTypeControlOptions: { 
 
     mapTypeIds: ['custom', google.maps.MapTypeId.ROADMAP], 
 
     style: google.maps.MapTypeControlStyle.DROPDOWN_MENU 
 
    } 
 

 
    }; 
 
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
 

 
    map.mapTypes.set('custom', CustomMapType); 
 
    map.setMapTypeId('custom'); 
 

 
    // To add the marker to the map, use the 'map' property 
 
    var marker = new google.maps.Marker({ 
 
    position: map.getCenter(), 
 
    map: map, 
 
    title: "Hello World!" 
 
    }); 
 
} 
 
google.maps.event.addDomListener(window, 'load', initialize); 
 

 
function CustomMapType() {} 
 
CustomMapType.prototype.tileSize = new google.maps.Size(256, 256); 
 
CustomMapType.prototype.maxZoom = 7; 
 
CustomMapType.prototype.getTile = function(coord, zoom, ownerDocument) { 
 
    var div = ownerDocument.createElement('DIV'); 
 
    var baseURL = 'http://d1m6g5gl70bc4l.cloudfront.net/'; 
 
    baseURL += zoom + '_' + coord.x + '_' + coord.y + '.png'; 
 
    div.style.width = this.tileSize.width + 'px'; 
 
    div.style.height = this.tileSize.height + 'px'; 
 
    div.style.backgroundColor = '#1B2D33'; 
 
    div.style.backgroundImage = 'url(' + baseURL + ')'; 
 
    return div; 
 
}; 
 

 
CustomMapType.prototype.name = "Custom"; 
 
CustomMapType.prototype.alt = "Tile Coordinate Map Type"; 
 
var map; 
 
var CustomMapType = new CustomMapType();
html { 
 
    height: 100% 
 
} 
 
body { 
 
    height: 100%; 
 
    margin: 0px; 
 
    padding: 0px 
 
} 
 
#map_canvas { 
 
    height: 100%; 
 
    z-index: 0; 
 
} 
 
#gmnoprint { 
 
    width: auto; 
 
}
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script> 
 
<div id="map_canvas" style="background: #1B2D33;"></div>

+0

這工作,非常感謝! – Best4bond 2014-12-05 11:02:06

相關問題