Пример #1
0
        public static List <MapLocation> YearMapLocations(FactDate when, int limit)
        {
            List <MapLocation> result = new List <MapLocation>();

            foreach (Individual ind in FamilyTree.Instance.AllIndividuals)
            {
                if (ind.IsAlive(when) && ind.GetMaxAge(when) < FactDate.MAXYEARS)
                {
                    Fact         fact = ind.BestLocationFact(when, limit);
                    FactLocation loc  = fact.Location;
                    if (loc.IsGeoCoded(false))
                    {
                        result.Add(new MapLocation(ind, fact, when));
                    }
                    else
                    {
                        int startlevel = loc.Level - 1;
                        for (int level = startlevel; level > FactLocation.UNKNOWN; level--)
                        {
                            loc = loc.GetLocation(level);
                            if (loc.IsGeoCoded(false))
                            {
                                result.Add(new MapLocation(ind, fact, loc, when));
                                break;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public bool SetLocation(FactLocation loc, int level)
        {
            while (!loaded)
            {
                Application.DoEvents();
            }
            GeoResponse.CResult.CGeometry.CViewPort viewport = null;
            GeoResponse res = null;

            Object[] args = new Object[] { 0, 0 };
            if (loc.IsGeoCoded(false) && loc.ViewPort != null)
            {
                labMapLevel.Text = "Previously Geocoded: " + loc.ToString();
                viewport         = MapTransforms.ReverseTransformViewport(loc.ViewPort);
                args             = new Object[] { loc.Latitude, loc.Longitude };
            }
            else
            {
                location = loc.ToString();
                res      = CallGoogleGeocode(location);
                if (res.Status == "OK")
                {
                    labMapLevel.Text = GoogleMap.LocationText(res, loc, level);
                    viewport         = res.Results[0].Geometry.ViewPort;
                    double lat = res.Results[0].Geometry.Location.Lat;
                    double lng = res.Results[0].Geometry.Location.Long;
                    args = new Object[] { lat, lng };
                }
                else if (res.Status == "OVER_QUERY_LIMIT" && loc.IsGeoCoded(false))
                {
                    labMapLevel.Text        = "Previously Geocoded: " + loc.ToString();
                    viewport                = new GeoResponse.CResult.CGeometry.CViewPort();
                    viewport.NorthEast.Lat  = loc.Latitude + 2;
                    viewport.NorthEast.Long = loc.Longitude + 2;
                    viewport.SouthWest.Lat  = loc.Latitude - 2;
                    viewport.SouthWest.Long = loc.Longitude - 2;
                    args = new Object[] { loc.Latitude, loc.Longitude };
                }
                else
                {
                    return(false);
                }
            }
            Object marker = webBrowser.Document.InvokeScript("frontAndCenter", args);

            args = new Object[] { viewport.NorthEast.Lat, viewport.NorthEast.Long, viewport.SouthWest.Lat, viewport.SouthWest.Long };
            webBrowser.Document.InvokeScript("setViewport", args);
            webBrowser.Show();
            return(true);
        }
Пример #3
0
        public static GeoResponse CallGoogleGeocode(FactLocation address, string text)
        {
            string bounds = string.Empty;
            string tld    = address.IsUnitedKingdom ? "&region=uk" : string.Empty;

            if (address != null)
            {
                //if (address.Level > FactLocation.SUBREGION)
                //{
                //    FactLocation area = address.GetLocation(FactLocation.SUBREGION);
                //    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                //        bounds = $"{area.Bounds}";
                //}
                if (string.IsNullOrEmpty(bounds) && address.Level > FactLocation.REGION)
                {
                    FactLocation area = address.GetLocation(FactLocation.REGION);
                    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                    {
                        bounds = $"{area.Bounds}";
                    }
                }
                if (string.IsNullOrEmpty(bounds) && address.Level > FactLocation.COUNTRY)
                {
                    FactLocation area = address.GetLocation(FactLocation.COUNTRY);
                    if (area != null && area.IsGeoCoded(false) && !string.IsNullOrEmpty(area.Bounds))
                    {
                        bounds = $"{area.Bounds}";
                    }
                }
            }
            string encodedAddress = HttpUtility.UrlEncode(text.Replace(" ", "+"));
            string url            = $"https://maps.googleapis.com/maps/api/geocode/json?address={encodedAddress}{bounds}{tld}&key={GoogleAPIKey.KeyValue}";

            return(GetGeoResponse(url));
        }
Пример #4
0
 public bool SetLocation(FactLocation loc, int level)
 {
     if (loc is null)
     {
         return(false);
     }
     while (!loaded)
     {
         Application.DoEvents();
     }
     GeoResponse.CResult.CGeometry.CViewPort viewport;
     if (loc.IsGeoCoded(false) && loc.ViewPort != null)
     {
         labMapLevel.Text = "Previously Geocoded: " + loc.ToString();
         viewport         = MapTransforms.ReverseTransformViewport(loc.ViewPort);
     }
     else
     {
         GeoResponse res = GoogleMap.CallGoogleGeocode(loc, loc.ToString());
         if (res.Status == "OK")
         {
             labMapLevel.Text = GoogleMap.LocationText(res, loc, level);
             viewport         = res.Results[0].Geometry.ViewPort;
         }
         else if (res.Status == "OVER_QUERY_LIMIT" && loc.IsGeoCoded(false))
         {
             labMapLevel.Text        = "Previously Geocoded: " + loc.ToString();
             viewport                = new GeoResponse.CResult.CGeometry.CViewPort();
             viewport.NorthEast.Lat  = loc.Latitude + 2;
             viewport.NorthEast.Long = loc.Longitude + 2;
             viewport.SouthWest.Lat  = loc.Latitude + 2;
             viewport.SouthWest.Long = loc.Longitude + 2;
         }
         else
         {
             return(false);
         }
     }
     object[] args = new object[] { viewport.NorthEast.Lat, viewport.NorthEast.Long, viewport.SouthWest.Lat, viewport.SouthWest.Long };
     webBrowser.Document.InvokeScript("setBounds", args);
     webBrowser.Show();
     return(true);
 }
Пример #5
0
 public void ShowLocation(FactLocation loc, int level)
 {
     if (loc.IsGeoCoded(false))
     {
         string URL = $"https://www.google.com/maps/@{loc.Latitude},{loc.Longitude},{level}z";
         SpecialMethods.VisitWebsite(URL);
     }
     else
     {
         MessageBox.Show($"{loc.ToString()} is not yet geocoded so can't be displayed.");
     }
 }
Пример #6
0
 void GoogleLocationSearch()
 {
     if (txtSearch.Text.Length > 0)
     {
         FactLocation loc = FactLocation.LookupLocation(txtSearch.Text);
         if (!loc.IsGeoCoded(false)) // if not geocoded then try database
         {
             DatabaseHelper.GetLocationDetails(loc);
         }
         if (loc.IsGeoCoded(false))
         {
             FactLocation.CopyLocationDetails(loc, location);
             SetLocation();
             pointUpdated = true;
         }
         else
         {
             GeoResponse res = GoogleMap.GoogleGeocode(txtSearch.Text, 8);
             if (res.Status == "OK" && !(res.Results[0].Geometry.Location.Lat == 0 && res.Results[0].Geometry.Location.Long == 0))
             {
                 loc.Latitude  = res.Results[0].Geometry.Location.Lat;
                 loc.Longitude = res.Results[0].Geometry.Location.Long;
                 Coordinate mpoint = MapTransforms.TransformCoordinate(new Coordinate(loc.Longitude, loc.Latitude));
                 loc.LongitudeM    = mpoint.X;
                 loc.LatitudeM     = mpoint.Y;
                 loc.ViewPort      = MapTransforms.TransformViewport(res.Results[0].Geometry.ViewPort);
                 loc.GeocodeStatus = res.Results[0].PartialMatch ? FactLocation.Geocode.PARTIAL_MATCH : FactLocation.Geocode.MATCHED;
                 FactLocation.CopyLocationDetails(loc, location);
                 SetLocation();
                 pointUpdated = true;
             }
             else
             {
                 MessageBox.Show("Google didn't find " + txtSearch.Text, "Failed Google Lookup");
             }
         }
     }
 }