- file_get_contents: documentation ( source)
- json_decode: documentation ( source)
- urlencode: documentation ( source)
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
$url = "http://geoip.nekudo.com/api/" . urlencode($ip);
$content = file_get_contents($url);
$json = json_decode($content);
$lat = $json->location->latitude;
$long = $json->location->longitude;
?>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCKpthp6RdaCNWy83Arx5N6LvwgLYMF2H4"></script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("map"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div align="center" class="map">
</div>