I have this code, which on clicked alert me the lat and lng of a place. How can i integrate google map to show the place in google map.
$("body").on("click",".names",function(){
var latitude = $(this).children(".latitude").text();
alert(latitude);
});
Thanks
Updata .. this is the database that i had made. So when i click on one of the list it alert me the lat n long. Instead of giving me alert of lat n lng. i want to show the place in google map. Hope this clarifies my point
$('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>
Are you looking for this?
$("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!'
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.