我想使用 2 个或更多 json 文件来生成标记(由于文件更短,更容易进行更改)。这些文件在构造上是相同的,但是当我将它们添加到我的代码中时,我只能从最后一个中获取详细信息。
我将数据重命名为 var jsonsl 和 var jsonpm,但似乎无法将两者合并。
我可以开始工作的代码是这样的,但一次只能处理一个文件。
<script type="text/javascript" src="js/mapping_1sl.js"></script>
<script type="text/javascript" src="js/mapping_1pm.js"></script>
var gmarkers = [];
function initialize() {
var latlng = new google.maps.LatLng(53.995391,-3.795069);
var myOptions = {
zoom: 6,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
};
var map = new google.maps.Map(document.getElementById("map"),myOptions);
var categoryIcons = {}
for (var i = 0; i < jsonsl.length; i++) {
var data = jsonsl[i],
latLng = new google.maps.LatLng(data.Latitude, data.Longitude);
var marker = new google.maps.Marker({
position: latLng,
map : map,
title : data.Name,
icon : categoryIcons[data.ConnectorType],
});
任何帮助或建议将不胜感激。
更多信息:
文件设置相同,只是名称不同:
var jsonsl = [{
"Name" : "2 Riddons Road",
"Latitude" : 51.43145362,
"Longitude" : 0.031174836,
"PostCode" : "SE12 9QR",
"Address" : "Riddons Road, jctn with Chinbrook Road, Lewisham , London, SE12 9QR",
"Count" : 1,
"Information" : "3-pin square",
"Connection" : "BS 1363",
"ChargeRate" : "Standard (up to 3.7kW, 13-16A)",
"ConnectorType" : 1,
"Operator" : "Source London",
}]
和
var jsonpm = [{
"Name" : "Cornthwaite Road",
"Latitude" : 51.55798957,
"Longitude" : -0.052563915,
"PostCode" : "E5 9QL",
"Address" : "Cornthwaite Road south of Thistlethwaite Road, Hackney, London, E5 9QL",
"Count" : 1,
"Information" : "7-pin 'Smart' eg Mennekes",
"Connection" : "IEC 62196 Fast",
"ChargeRate" : "Fast (7kW, 32A)",
"ConnectorType" : 2,
"Operator" : "Source London",
}]