[英]google map lat lon not working
我试图通过我的链接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);
获得文本纬度,但没有任何价值。
如果lat和lon最终以所需值的文本表示形式出现,则应分析浮点数。
var lat = parseFloat( $(this).attr('id1') ),
lon = parseFloat( $(this).attr('id2') );
我对Android的知识为零,并且不知道什么是'。$ cd [$ i] [9]。 作为值获取,但在您的情况下,可能不是数字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.