通过JS在谷歌地图中显示访问者的位置

Showing visitors locations in Google Maps via JS

本文关键字:访问者 位置 显示 JS 谷歌地图 通过      更新时间:2023-09-26

所以,我有一个JavaScript代码,显示地图和我的位置。它还应用了一些额外的设置。我的问题是,看看下面的JS代码,并在这里使用GoogleMaps API:http://maps.googleapis.com/maps/api/js?sensor=false,有没有办法在这张地图上显示游客的位置?

我正在尝试构建一个虚拟站点视图GeoLocator。这显示了我所有网站观众的位置。或者,也许有一个插件在线。

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);
});
}

好吧,这是可能的。。。您需要一个服务器来将这些信息发送到(您必须在查看者访问的页面上设置该服务器),该服务器将找到他们的IP,并在IP数据库上查找他们的long/lat,如果该IP是已知的(该信息并不总是存在,如果是,也不一定准确)。然后,您需要一个接口,从这个数据库中获取long/lat值,并将它们用标记显示在地图上,正如我在评论中所描述的那样。

当然,你也可以使用谷歌分析(Google.com/Analytics),所有这些都是为你完成的。:)