public ActionResult Index(VisitorLocationPage currentPage)
        {
            var viewmodel = new VisitorLocationPageViewModel(currentPage);

            viewmodel.IPAddress         = GetIPAddress(Request);
            viewmodel.GeolocationResult = geolocationProvider.Lookup(viewmodel.IPAddress);

            viewmodel.GoogleMapSrc = "https://www.google.com/maps/embed/v1/view" +
                                     "?key=YOUR_API_KEY" +
                                     "&center=" +
                                     viewmodel.GeolocationResult.Location.Latitude + "," +
                                     viewmodel.GeolocationResult.Location.Longitude +
                                     "&zoom=18" +
                                     "&maptype=satellite";

            if (viewmodel.GeolocationResult != null)
            {
                Response.Cookies.Add(new HttpCookie("epi-visitor-country-code",
                                                    viewmodel.GeolocationResult.CountryCode)
                {
                    Expires = DateTime.Now.AddDays(90)
                });
            }

            return(View("~/Features/VisitorLocation/VisitorLocationPage.cshtml", viewmodel));
        }
Exemplo n.º 2
0
 public IGeolocationResult GetLocation(IPAddress ipAddress)
 {
     try
     {
         var result = _geolocationProvider.Lookup(ipAddress);
         return(result);
     }
     catch
     {
         return(null);
     }
 }
        public static IGeolocationResult GetLocationFromIp(IPAddress IpAddress)
        {
            IGeolocationProvider provider = GetProvider();

            if (provider == null)
            {
                // We have no way to convert IP to lat/long.
                Debug.WriteLine("GeoLocationHelper.GetProvider(): Pulse requires a Geolocation Provider in order to function. Please install the MaxMind Geolocation Provider for Episerver.");
                return(null);
            }

            return(provider.Lookup(IpAddress));
        }