【问题标题】:Load map Lon & Lat to script inside html is not working将地图 Lon & Lat 加载到 html 中的脚本不起作用
【发布时间】:2014-05-26 07:35:43
【问题描述】:

从数据库到脚本和加载到脚本的地图纬度和经度值工作正常,但地图没有显示

这是脚本

var geocoder;
var map;

function initialize() {
geocoder = new google.maps.Geocoder();
var loc= document.getElementById('loc');

alert(loc.innerHTML);
var latlng = new google.maps.LatLng('+loc+');
var myOptions = {
  zoom: 8,
  center: latlng,
mapTypeControl: false,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: false,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
if (geocoder) {
  geocoder.geocode( {  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
      map.setCenter(results[0].geometry.location);

        var infowindow = new google.maps.InfoWindow(
            { 
              size: new google.maps.Size(150,50)
            });

        var marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map, 
            title:address
        }); 
        google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker);
        });

      } else {

      }
    } else {

    }
  });
}
}

HTML

<div id="map_canvas" style="width: 270px; height: 267px;">
</div>

警报显示值 10.52722212213278, 76.20814598432844

但地图没有加载

如果你知道这个请分享答案

【问题讨论】:

    标签: javascript html map


    【解决方案1】:

    替换这个

    var latlng = new google.maps.LatLng("Lat", "Long");
    

    var loc= document.getElementById('loc'); //Remove This
    var latlng = new google.maps.LatLng('+loc+'); //Remove This
    

    添加具有两个单独坐标的线,即“Lat”、“Long”,如我的代码所示

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 2013-11-13
      相关资源
      最近更新 更多