¡Ayúdanos a traducir esta Web y consigue licencias gratis!
Usuario anónimo  |  Ingresar  |  Regístrate

Cómo...

GeoIP

Gracias a MaxMind disponemos de la Geolocalización por IP: a partir de una IP conseguiremos datos sobre su localización, entre otros la latitud y la longitud.

Para ello sólo hay que usar el código del ejemplo y descargarse la base de datos de MaxMind (descargar directa).




Code.aspx
<cc1:GMap ID="GMap1" runat="server" />
Code.aspx.cs
string databaseFile = Server.MapPath("~/App_Data/GeoIP/GeoLiteCity.dat");
LookupService service = new LookupService(databaseFile);
Location location = service.getLocation(Request.UserHostAddress);

if (location != null)
{
    GLatLng latlng = new GLatLng(location.latitude, location.longitude);
    GMap1.setCenter(latlng, 10);

    string infoWindowHTML = string.Format(@"
        <div style=""text-align:left"">
            <b>GEOIP PROPERTIES</b>
            <br />
            <b>Area Code</b>: {0}
            <br />
            <b>City</b>: {1}
            <br />
            <b>Country Code</b>: {2}
            <br />
            <b>Country Name</b>: {3}
            <br />
            <b>DMA Code</b>: {4}
            <br />
            <b>Postal Code</b>: {5}
            <br />
            <b>Region</b>: {6}
        </div>
        ", 
         location.area_code,
         location.city,
         location.countryCode,
         location.countryName,
         location.dma_code,
         location.postalCode,
         location.region);

    GMap1.Add(new GInfoWindow(new GMarker(latlng), infoWindowHTML));
}
Powered by Subgurim.NET