【发布时间】: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