Javascript 如何将onclick函数与googlemap链接
我有这个代码,点击后会提醒我某个地方的lat和lng。如何集成谷歌地图以显示谷歌地图中的位置Javascript 如何将onclick函数与googlemap链接,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有这个代码,点击后会提醒我某个地方的lat和lng。如何集成谷歌地图以显示谷歌地图中的位置 $("body").on("click",".names",function(){ var latitude = $(this).children(".latitude").text(); alert(latitude); }); 谢谢 更新。。这是我制作的数据库。因此,当我点击其中一个列表时,它会提醒我该列表的长度。而不是给我关于lat n lng的警报。
$("body").on("click",".names",function(){
var latitude = $(this).children(".latitude").text();
alert(latitude);
});
谢谢
更新。。这是我制作的数据库。因此,当我点击其中一个列表时,它会提醒我该列表的长度。而不是给我关于lat n lng的警报。我想在谷歌地图上显示这个地方。希望这能澄清我的观点
$('document').ready(function(){
var db = openDatabase('To Do', '1.0', 'To Do', 2 * 1024 * 1024);
db.transaction(function(tx){
tx.executeSql('SELECT * FROM BNames', [], querySucess, errorCB);
});
function querySucess(tx, results){
var len = results.rows.length;
if(len > 0){
for(i = 0; i < len; i++){ //<span here>//
$("#list").append("<ul><li class='names'<br>" + results.rows.item(i).id + " "+ results.rows.item(i).name + "<span class='latitude'> " + results.rows.item(i).latitude + "</span><span class='latitude'> " + results.rows.item(i).longtitude +" </span> [<a href='#' onclick='deletefunction(" + results.rows.item(i).id + ");'>DELETE</a>] </li></ul>");
}
}else{
console.log("You Have No BuildingNames");
}
}
function errorCB(err){
alert("Error" + err.code);
}
});
HTML
<!DOCTYPE>
<html>
<body>
<input type="text" id="name" placeholder="BName"/>
<input type="text" id="latitude" placeholder="latitude"/>
<input type="text" id="longitude" placeholder="longitude"/>
<input type="button" id="Add" value="Add"/>
<div id="list"> </div>
<div id="map-canvas"></div>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>
你在找这个吗
$("body").on("click",".names",function(){
//next two lines most likely need replacing.
var latitude = $("#latitude").text();
var longitude = $("#longitude").text();
var myLatlng = new google.maps.LatLng(parseFloat(latitude), parseFloat(longitude));
var mapOptions = {
zoom: 4,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Hello World!'
});
});
首先,你还需要得到经度。这段代码似乎给了你一个纬度,它会同时显示纬度和经度。。纬度的子元素是经度。这可能有助于向我们显示您的单击事件绑定到的HTML的内容是这样的。。当我点击列表而不是给我提示时,它会告诉我cordinate在谷歌地图上的位置