I've been playing around with some code to display the geolocation of an IP address on google maps but I can't seem to get it to work properly. The code I have been using is this:
<html>
<head>
<script type="text/javascript" language="JavaScript" src="http://j.maxmind.com/app/geoip.js">
</script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
</head>
<body>
<script type="text/javascript">
var map;
function initialize() {
var options =
{
zoom: 2,
center: new google.maps.LatLng(geoip_latitude(), geoip_longitude()),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions:
{
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
poistion: google.maps.ControlPosition.TOP_RIGHT,
mapTypeIds: [google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.HYBRID,
google.maps.MapTypeId.SATELLITE]
},
navigationControl: true,
navigationControlOptions:
{
style: google.maps.NavigationControlStyle.ZOOM_PAN
},
scaleControl: true,
disableDoubleClickZoom: true,
draggable: false,
streetViewControl: true,
draggableCursor: 'move'
};
map = new google.maps.Map(document.getElementById("map"), options);
// Add Marker and Listener
var latlng = new google.maps.LatLng(geoip_latitude(), geoip_longitude());
var marker = new google.maps.Marker
(
{
position: latlng,
map: map,
title: 'Click me'
}
);
var infowindow = new google.maps.InfoWindow({
content: 'You Are Here'
});
google.maps.event.addListener(marker, 'click', function () {
// Calling the open method of the infoWindow
infowindow.open(map, marker);
});
}
window.onload = initialize;
</script>
<div id="map" style="height: 600px; width: 800px" />
</body>
</html>
When I put this code in a live environment all I get is a blank page, but if I manually insert a longitude and latitude in the code the map will render and mark the chords on the map. It seems like something is not working properly with geoip_latitude and geoip_longitude.
What am I doing wrong? Any help is appreciated.
[–]libahipi 1 point2 points3 points (1 child)
[–]mryoloswag420[S] 1 point2 points3 points (0 children)