Questions:
Hi,
I want to embed a dynamic google map in my website by IP address. I got the lat/long data using IPlocation tools. I could not yet connect the lat/log data from IPlocation to google map java codes. I m not sure how to format/define/put latitude and longitude in load map function. here are things I tried and did not work yet:
- I tried , into javascript code,
- I also tried manually putting values for $latitude and $longitude.
- I tried directly putting 'ip2location_latitude()' and 'ip2location_longitude()' in java codes.
eventually I need to get a location history based on IP and record the location data to a database.
Thanks in advance
here is the summary of my code:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <!-- Google map API v3 -->
<?php
$latitude = 'ip2location_latitude()'; //------------ IP latitude
$longitude = 'ip2location_longitude()'; //------------ IP latitude ip2location_longitude()
?>
<!-- Start loading canvas google map -->
<script type="text/javascript">
function loadmap () {
var latlng = new google.maps.LatLng($latitude,$longitude);
var option = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), option);
createMarker(latitude,logitude, 'lol');
downloadUrl("airport.xml", function(data) {
var xml = xmlParse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
document.getElementById("test").innerHTML = markers.length;
for (var i = 0; i < markers.length; i++) {
var info = markers[i].getAttribute("info");
var lat = parseFloat(markers[i].getAttribute("lat"));
var lon = parseFloat(markers[i].getAttribute("lng"));
createMarker(lat, lon, info);
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function createMarker(lat, lon, info){
var myLatlng = new google.maps.LatLng($latitude,$longitude);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"My location",
icon: "http://google-maps-icons.googlecode.com/files/airport.png"
});
}
</script>
<!-- End Geting map via latitude and longitude-->
<!-- Start calling load map function to load the map -->
<body onload="loadmap ()">
<div id="map_canvas" style="width:400px; height:300px"></div>
<div id="test" style="width:50%; height:50%"></div>
<!-- End calling load map function to load the map -->