2010-11-19 99 views
0

我嘗試從用戶登錄到我的django應用程序時從IP地址獲取用戶位置。 ,但不知道如何完全做到這一點。我爲此使用GeoIP。 我的問題是 如何爲此目的編寫視圖,以及如何顯示IP地址在谷歌地圖上的位置。在谷歌地圖上顯示IP位置

+0

我使用的是Django和GeoIP,並且需要一些關於如何爲此目的編寫視圖的線索 – MajorGeek 2010-11-19 23:49:09

回答

0

顯示geoip的一個谷歌地圖上你可以http://freegeoip.net/json/使用免費geoip的服務,並繪製地圖點如下:

var geoLocations = getLocations(); 
    var center = getCenter(); 
    var map = new google.maps.Map(document.getElementById('googlemap'), 
    { 
     zoom: 1, 
     center: new google.maps.LatLng(center[0], center[1]), 
     mapTypeId: google.maps.MapTypeId.SATELLITE 
    }); 
    var markerInfo = new google.maps.InfoWindow(); 
    var pointMarker, i; 
    // Go through the location array... 
    for (i = 0; i < geoLocations.length; i++) 
    { 
     // Add the marker. 
     pointMarker = new google.maps.Marker(
      { 
       position: new google.maps.LatLng(geoLocations[i][1], geoLocations[i][2]), 
       map: map 
      }); 
     // Add the information window when clicking the marker 
     google.maps.event.addListener(pointMarker, 'click', (function(pointMarker, i) 
     {  
      return function() 
      { 
       markerInfo.setContent(geoLocations[i][0] + ' -> ' + geoLocations[i][3]); 
       markerInfo.open(map, pointMarker); 
      } 
     })(pointMarker, i)); 

     // Zoom on double click 
     google.maps.event.addListener(pointMarker, 'dblclick', (function(pointMarker, i) 
     {  
      return function() 
      { 
       map.setZoom(17); 
      } 
     })(pointMarker, i));    
    } 

示例代碼使用python您撥打免費geoip的服務可以在這裏找到: https://github.com/jamesrep/geoipard