Google Maps API自定义标记

时间:2013-07-15 18:31:00

标签: google-maps-api-3 google-api google-maps-markers

我正在尝试使用各种形状和颜色的自定义标记图标创建地图。我的代码工作正常,我可以为所有位置使用任何单个标记,但不能为不同位置使用不同的标记。我目前正在将其编程为FileMaker Pro解决方案,但我正在用Javascript编写代码。我是Javascript的新手,我正在接受我的工作,但下面是我到目前为止的代码:

var concus = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/red_customer.png';
var rencus = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/purple_customer.png';
var sercus = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/green_customer.png';
var connon = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/red_noncustomer.png';
var rennon = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/purple_noncustomer.png';
var sernon = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/green_noncustomer.png';

var imagenum;

var markers = [];
for (var i = 0; i < data.length; ++i) {
  var latlng = new google.maps.LatLng(data[i].latitude, data[i].longitude);
  var marker = new google.maps.Marker({position: latlng, map: map, icon: markerimage[i], title:data[i].label, info:data[i].info});

  markers.push(marker);
}
“markerimage”在“icon:”之后是从我的数据库中存储值“concus,rencus,sercus ......等”的数组。如果我将“markerimage”替换为任何特定的脚本,并向我显示一张包含所有位置的地图。如果我使用markerimage,我只会得到一张没有任何内容的地图。

非常感谢任何帮助!

扎克

1 个答案:

答案 0 :(得分:0)

试试这个:

var iconBase = 'Dropbox/FileMaker Pro Files/FileMaker Pro Contract Bid Files/Images/';

var icons = {
  concus: {
    icon: iconBase + 'red_customer.png'
  },
  rencus: {
    icon: iconBase + 'purple_customer.png'
  },
  sercus: {
    icon: iconBase + 'green_customer.png'
  },
  connon: {
    icon: iconBase + 'red_noncustomer.png'
  },
  rennon: {
    icon: iconBase + 'purple_noncustomer.png'
  },
  sernon: {
    icon: iconBase + 'green_noncustomer.png'
  }
};


function addMarker(feature) {
  var marker = new google.maps.Marker({
    position: feature.position,
    icon: icons[feature.type].icon,
    map: map
  });
}