2

我是 jQuery 新手,一直在玩 jQuery 商店定位器插件。

我想要做的是,将标记从字母标记更改为带有黑点的普通标记。我试过这样做,但不断收到语法错误或根本没有出现任何问题。

我一直在尝试做的另一件事是在屏幕上显示多个商店定位器或显示多个 XML 文件。这可能吗?我已经尝试过,但没有得到任何结果。

最后,我想知道是否可以让多个 XML 文件正常工作?是否可以说 4 个主要标记,然后当用户按下红色标记说五金店时,地图将只显示所有五金店,或者他/她按下蓝色标记说他/她只得到杂货店?

我希望这是有道理的,如果之前有人问过这个问题,我很抱歉。我找不到任何关于它的信息。

抱歉延迟回复

jquery.storelocator.js

这是我无法编辑的代码。每次我尝试更改 var pinImage 行时,都会出现语法错误

//Custom marker function - aplhabetical
  function createMarker(point, letter, pinColor) {
//Set up pin icon with the Google Charts API for all of our markers

  var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=" + letter + "|" + pinColor + "|" + settings.pinTextColor,

  new google.maps.Size(21, 34),
  new google.maps.Point(0, 0),
  new google.maps.Point(10, 34));
  var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
  new google.maps.Size(40, 37),
  new google.maps.Point(0, 0),
  new google.maps.Point(12, 35));

 //Create the markers
   return new google.maps.Marker({
   position: point,
   map: map,
   icon: pinImage,
   shadow: pinShadow,
   draggable: false

上述代码的编辑版本

//Custom marker function - aplhabetical
  function createMarker(point, letter, pinColor) {
//Set up pin icon with the Google Charts API for all of our markers

  var pinImage = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=" + location + "|" + pinColor + "|" + settings.pinTextColor,

  new google.maps.Size(21, 34),
  new google.maps.Point(0, 0),
  new google.maps.Point(10, 34));
  var pinShadow = new google.maps.MarkerImage("http://chart.apis.google.com/chart?chst=d_map_pin_shadow",
  new google.maps.Size(40, 37),
  new google.maps.Point(0, 0),
  new google.maps.Point(12, 35));

 //Create the markers
   return new google.maps.Marker({
   position: point,
   map: map,
   icon: pinImage,
   shadow: pinShadow,
   draggable: false
4

2 回答 2

1

感谢您对标记位的帮助。

是的,我为每个商店使用单个 xml,这是我用于每个 xml 的代码

鳟鱼.xml

<?xml version="1.0" encoding="UTF-8"?>
  <kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>trout</name>
<description><![CDATA[Trout fishing (plain text version)]]></description>
<Placemark>
<name>some trout place - burnley</name>
<Snippet>some trout place in burnley </Snippet>
<description><![CDATA[<div dir="ltr">trout place 1 - burnley<br>some street<br>bb12 3ab<br>01234 567890</div>]]></description>
<Point>
  <coordinates>-2.104521,57.145737,0.000000</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Nelson</name>
<Snippet>Some trout place nelson</Snippet>
<description><![CDATA[<div dir="ltr">Some trout place nelson1 <br>some street<br>Nelson<br>Bb12 3ac<br>01234 567890</div>]]></description>
<Point>
  <coordinates>-5.962432,54.570358,0.000000</coordinates>
</Point>

三文鱼.xml

<?xml version="1.0" encoding="UTF-8"?>
 <kml xmlns="http://earth.google.com/kml/2.2">
<Document>
<name>Salmon</name>
<description><![CDATA[salmon fishing in the uk (plain text version)]]></description>
<Placemark>
<name>Burnley</name>
<Snippet>Salmon fishing place1 goes here</Snippet>
<description><![CDATA[<div dir="ltr">Salmon Fishing Place - Burnley<br>Some Street<br>Burnley<br>bb12 3ab<br>01234 567890</div>]]></description>
<Point>
  <coordinates>-2.2450,53.7877,0.000000</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Nelson</name>
<Snippet>Salmon fishing place2 goes herei</Snippet>
<description><![CDATA[<div dir="ltr">Salmon Fishing place2 - Nelson<br>Some Street<br>Nelson<br>BB12 3ac<br>01234 567890</div>]]></description>
<Point>
  <coordinates>-5.962432,54.570358,0.000000</coordinates>
</Point>
</Placemark>

这是我放置文件的地方

jQuery.storelocator.js

(function ($) {
$.fn.storeLocator = function (options) {

    var settings = $.extend({
        'mapDiv': 'map',
        'listDiv': 'list',
        'formID': 'user-location',
        'pinColor': 'fe7569',
        'startPinColor': '66bd4a',
        'pinTextColor': '000000',
        'storeLimit': 10,
        'distanceAlert': 60,
        'xmlLocation': 'data/trout.xml',
        'xmlLocation': 'data/salmon.xml',
        'addressErrorMsg': 'Please enter valid UK address address or postcode',
        'googleDistanceMatrixDestinationLimit': 25,
        'defaultLat': 52.3038165,
        'defaultLng': -1.081117,
        'defaultLocationName': 'Northampton, United Kingdom'
    }, options);

    return this.each(function () {
        var $this = $(this);

        // global array of shop objects
        var _locationset = new Array();
        var geocoder;
于 2012-05-20T15:25:33.350 回答
0

您想放弃自定义字母标记并使用简单的“默认”标记吗?我理解对了吗?它应该像折腾所有额外的选项并将函数简化为这样简单:

//Custom marker function
  function createMarker(point) {

 //Create the markers
   return new google.maps.Marker({
   position: point,
   map: map,
   draggable: false
   });
  }

关于多个 XML 文件,我尝试过的最接近的方法是放置多个 KmlLayers,它可以工作。如果您正在从多个 XML 中读取数据,我相信构建信息应该可以正常工作。你可以说得更详细点吗?每种类型的商店都使用一个 XML 文件吗?向我们展示您为多个 XML 编写的代码?

于 2012-05-20T14:59:29.057 回答