我正在尝试使用地图API绘制多个标记,但地图不是绘图,我已经发布了下面的代码,希望有人能帮助我解决问题。 最初,当我只有承包商和latlongs变量时,地图和标记都是绘图,但是当我添加客户端和名称变量时,地图拒绝绘图。 我是编程新手,知道我错过了这里的一些东西。 感谢。
var locations = [ ['承包商:Lee Construction Ltd', - 1.32021,36.82789,'客户:县','名称:项目1',1], ['承包商:Intex Africa Limited', - 1.27942,66.83980,'客户:县','名称:项目1',2], ['承包商:Oriental Company Limited', - 1.3410701,36.75760,'客户:县','名称:Project2',3], ['承包商:Axis Architects',-1.29805,36.78690,'客户:国家政府','名称:项目3',4], ['承包商:Becam Properties Ltd', - 1.24511,36.76830,'客户:当地政府','名称:项目4',5], ['承包商:Chania Gardens Limited',-1.2169,36.86180,'客户:非政府组织','名称:项目5',6], ['Contractor:Dimension Architects', - 1.23793,36.80990,'Client:Parastatal','Name:Project 6',7], ['承包商:Gibb Africa Ltd', - 1.25713,36.88110,'客户:当地政府',姓名:Project 7',8], ['承包商:Selengei有限公司',-1.2830,36.81780,'客户:非政府组织','名称:项目7',9], ['承包商:Msingi Africa Ltd', - 1.2556601,36.8325005,'客户:当地政府','名称:项目8',10], ['承包商:Frame Consultants Ltd',-1.31691,36.7182007,'客户:县政府','名称:项目9',11], ['承包商:Mentor Group',-1.29862,36.7574997,'客户:国家政府','名称:项目10',12], ['承包商:CUAK开发商',-1.27955,36.8095016,'客户:私人','名称:项目11',13], ['Contractor:East Africa Ltd', - 1.29074,36.8824997,'Client:Private','Name:Project 12',14], ['承包商:Montezuma有限公司',-1.31801,36.8642006,'客户:私人','名称:项目13',15] ]。 var map = new google.maps.Map(document.getElementById('map'),{ zoom:13, center:new google.maps.LatLng(-1.32021,36.82789), mapTypeId:google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow(); var marker,i; for(i = 0; i</body>
</html>
答案 0 :(得分:0)
嘿,请查看脚本,您将在地图上看到多个标记
这是工作的HTML文件https://www.dropbox.com/s/0rwnro6vz9d9orv/googlemaps.html?dl=0
var map;
var locations = [
['Contractor: Lee Construction Ltd', -1.32021, 36.82789, 'Client: County', 'Name: project 1', 1],
['Contractor: Intex Africa Limited', -1.27942, 36.83980, 'Client: County', 'Name: project 1', 2],
['Contractor: Oriental Company Limited', -1.3410701, 36.75760, 'Client: county', 'Name:Project2', 3],
['Contractor: Axis Architects', -1.29805, 36.78690, 'Client: National govt', 'Name:Project 3', 4],
['Contractor: Becam Properties Ltd', -1.24511, 36.76830, 'Client: Local Govt', 'Name:Project 4', 5],
['Contractor: Chania Gardens Limited', -1.2169, 36.86180, 'Client: NGO', 'Name:Project 5', 6],
['Contractor: Dimension Architects', -1.23793, 36.80990, 'Client: Parastatal', 'Name:Project 6', 7],
['Contractor: Gibb Africa Ltd', -1.25713, 36.88110, 'Client: Local Govt', 'Name:Project 7', 8],
['Contractor: Selengei Limited', -1.2830, 36.81780, 'Client: NGO', 'Name:Project 7', 9],
['Contractor: Msingi Africa Ltd', -1.2556601, 36.8325005, 'Client: Local Govt', 'Name:Project 8', 10],
['Contractor: Frame Consultants Ltd', -1.31691, 36.7182007, 'Client: County govt', 'Name:Project 9', 11],
['Contractor: Mentor Group', -1.29862, 36.7574997, 'Client: National Govt', 'Name:project 10', 12],
['Contractor: CUAK Developers', -1.27955, 36.8095016, 'Client: Private', 'Name:Project 11', 13],
['Contractor: East Africa Ltd', -1.29074, 36.8824997, 'Client: Private', 'Name:Project 12', 14],
['Contractor: Montezuma Limited', -1.31801, 36.8642006, 'Client: Private', 'Name:Project 13', 15]
];
var k = 0;
$(document).ready(function () {
var mapOptions = {
zoom: 13,
center: new google.maps.LatLng(43, 0)
};
map = new google.maps.Map($('#mapcanvas')[0], mapOptions);
var marker = null;
for (i = 0; i < locations.length; i++) {
navigator.geolocation.getCurrentPosition(function (position) {
var newPoint = new google.maps.LatLng(locations[k][1], locations[k][1]);
marker = new google.maps.Marker({
position: newPoint,
map: map
});
var infowindow = new google.maps.InfoWindow({
content: locations[k][0]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
k++;
});
}
});