谷歌地图经度纬度定义了两次

时间:2014-02-28 15:46:25

标签: javascript jquery google-maps

我想定义一次经度纬度。现在它只有在定义了两次才有效。

我已经移动了一些东西,但我所管理的只是一张破碎的地图。字体图标仅显示long和lat在那里两次。

这是我的代码:

function initialize() {

  var mapOptions = {
    center: new google.maps.LatLng(27.86336,-101.130738),
    zoom: 16,
    disableDefaultUI: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  var map = new google.maps.Map(document.getElementById("google-map"), mapOptions);

  new google.maps.Marker({
    map: map,
    icon: {
      path: fontawesome.markers.EXCLAMATION,
      scale: 0.5,
      strokeWeight: 0,
      strokeColor: 'transparent',
      strokeOpacity: 0,
      fillColor: 'red',
      fillOpacity: 1,
    },
    clickable: false,
    position: new google.maps.LatLng(27.86336,-101.130738)
  });

}

google.maps.event.addDomListener(window, "load", initialize);

我已使用此处的字体标记解决方案:Using Icon Fonts as Markers in Google Maps V3如果有帮助

1 个答案:

答案 0 :(得分:1)

你只能这样做:

function initialize() {
  var myLatLng = new google.maps.LatLng(27.86336. -101.130738);

  var mapOptions = {
    center: myLatLng,
    zoom: 16,
    disableDefaultUI: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  var map = new google.maps.Map(document.getElementById("google-map"), mapOptions);

  new google.maps.Marker({
    map: map,
    icon: {
      path: fontawesome.markers.EXCLAMATION,
      scale: 0.5,
      strokeWeight: 0,
      strokeColor: 'transparent',
      strokeOpacity: 0,
      fillColor: 'red',
      fillOpacity: 1,
    },
    clickable: false,
    position: myLatLng
  });

}

google.maps.event.addDomListener(window, "load", initialize);

只要您在范围内声明变量,您就不会有任何问题吗?