【问题标题】:google map lat lon not working谷歌地图经纬度不起作用
【发布时间】:2014-03-16 15:52:23
【问题描述】:

我试图从我的链接 id 值 id 中获取谷歌地图的纬度和经度,但它不起作用。id 总是得到文本值而不是 id 值

我的代码

var map;
$(document).ready(function(){
    // listen for clicks on that element
    $('.android').on('click', function(){
        // get the data
        var lat = $(this).attr('id1'),
            lon = $(this).attr('id2');
        // send the data to you function. There are 10 other ways to do this but this'll work.
        initialize(lat, lon);
    });

}); 
function initialize(lat, lon) {




var myLatlng = new google.maps.LatLng(lat,lon);
  var mapOptions = {
    zoom: 16,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var marker = new google.maps.Marker({
      position: myLatlng,
      animation: google.maps.Animation.DROP,
      map: map
  });

}

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


<a class="android" data-toggle="modal" id1="'.$cd[$i][9].'" id2="'.$cd[$i][10].'" href="#myMapModal" class="btn btn-info">View On Map</a>

但总是var myLatlng = new google.maps.LatLng(lat,lon); 获取文本经纬度但没有任何值。

【问题讨论】:

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


    【解决方案1】:

    如果 lat 和 lon 最终成为所需值的文本表示,那么您应该解析浮点数。

    var lat = parseFloat( $(this).attr('id1') ),
        lon = parseFloat( $(this).attr('id2') );
    

    我对 Android 的了解为零,也不知道 '.$cd[$i][9].' 是什么。获取一个值,但在你的情况下它可能不是一个数字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多