0
votes

So, I have a JavaScript code that shows a map, and my location. It also has a few extra settings applied to it. My question is, looking at the following JS code, and using the GoogleMaps API here: http://maps.googleapis.com/maps/api/js?sensor=false, is there any way to show the visitors locations on this map?

I am trying t build a virtual site view GeoLocator. That shows the locations of all my sites viewers. Or, maybe there is a plugin online.

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: true,
    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);
});
}
1
What do you mean by "show the visitors locations"? - Hamza Kubba
@Hamza Kubba : Show the little red 'blips' of each visitor that has visited the site. - user3267537
Okay... so are the visitors' coordinates available to this script somehow? If they are, you just iterate over them (for loop) and make a new google.maps.Marker(), a new google.maps.InfoWindow() and a new event listener for each one. - Hamza Kubba
I actually do not know how make the visitors coordinates available to the view map, maybe every time a viewer views the page, it tracks their IP and saves it to a Db? Then, displays them on the map? - user3267537
Well, that's possible... you would need a server to send this information to (which you would have to set up on the page that the viewers visit), that would find their IP and lookup their long/lat on an IP database, if that IP is known (that information is not always there and not necessarily accurate, if it is). Then you would need to have an interface that gets the long/lat values from this database and displays them on the map with markers, as I described on my previous comment. - Hamza Kubba

1 Answers

0
votes

Well, that's possible... you would need a server to send this information to (which you would have to set up on the page that the viewers visit), that would find their IP and lookup their long/lat on an IP database, if that IP is known (that information is not always there and not necessarily accurate, if it is). Then you would need to have an interface that gets the long/lat values from this database and displays them on the map with markers, as I described on my comment.

Of course, you can also just use Google Analytics (google.com/analytics) where all of this is done for you. :)