Пример #1
0
        public GeoCoderStatusCode GetPoints(Placemark placemark, out List <PointLatLng> pointList)
        {
            // http://nominatim.openstreetmap.org/search?street=&city=vilnius&county=&state=&country=lithuania&postalcode=&format=xml

            #region -- response --
            //<searchresults timestamp="Thu, 29 Nov 12 08:38:23 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="vilnius, lithuania" polygon="false" exclude_place_ids="98093941" more_url="http://nominatim.openstreetmap.org/search?format=xml&exclude_place_ids=98093941&accept-language=de-de,de;q=0.8,en-us;q=0.5,en;q=0.3&q=vilnius%2C+lithuania">
            //<place place_id="98093941" osm_type="relation" osm_id="1529146" place_rank="16" boundingbox="54.5693359375,54.8323097229004,25.0250644683838,25.4815216064453" lat="54.6843135" lon="25.2853984" display_name="Vilnius, Vilniaus m. savivaldybė, Distrikt Vilnius, Litauen" class="boundary" type="administrative" icon="http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png"/>
            //</searchresults>
            #endregion

            return(GetLatLngFromGeocoderUrl(MakeDetailedGeocoderUrl(placemark), out pointList));
        }
        private async Task OnOpenPlantMap(string arg)
        {
            var placemark = new Placemark
            {
                Thoroughfare = CorporateAddress
            };
            var options = new MapLaunchOptions {
                Name = "Trulite Glass & Aluminum Solutions"
            };

            await Map.OpenAsync(placemark, options);
        }
Пример #3
0
 public async Task OpenAsync(Placemark placemark, MapLaunchOptions options)
 {
     try
     {
         await Xamarin.Essentials.Map.OpenAsync(placemark, options);
     }
     catch (Exception ex)
     {
         // No map application available to open or placemark can not be located
         _eventTracker.Error(ex);
     }
 }
Пример #4
0
        private async Task <List <Placemark> > GetLinesOfCommand(RenderEntry data)
        {
            var placemarks = new List <Placemark>();

            if (!data.Entry.What.Hierarchy.Any())
            {
                return(placemarks);
            }



            data.Entry.What.Hierarchy
            .Where(h => h.Superior.Equals(data.Entry.What))
            .Where(h => WasPresent(data.Entry.When.StartDateTime.DateTime, data.Entry.When.EndDateTime?.DateTime, h.StartDateTime.DateTime, h.EndDateTime?.DateTime))
            .ToList()
            .ForEach(h =>
            {
                var superiorLocation = data.Entry.Where;
                if (!superiorLocation.Latitude.HasValue || !superiorLocation.Longtitude.HasValue)
                {
                    return;
                }


                var inferiorLocations = h.Inferior.Locations.Where(l => WasPresent(l.StartDateTime.DateTime, l.EndDateTime?.DateTime, h.StartDateTime.DateTime, h.EndDateTime?.DateTime)).ToList();
                inferiorLocations.ForEach(il =>
                {
                    if (!il.Location.Latitude.HasValue || !il.Location.Longtitude.HasValue)
                    {
                        return;
                    }
                    var lineString         = new LineString();
                    lineString.Coordinates = new CoordinateCollection();
                    lineString.Coordinates.Add(new SharpKml.Base.Vector(superiorLocation.Latitude.Value, superiorLocation.Longtitude.Value));
                    lineString.Coordinates.Add(new SharpKml.Base.Vector(il.Location.Latitude.Value, il.Location.Longtitude.Value));


                    var placemark = new Placemark
                    {
                        Geometry = lineString,
                        Name     = data.Entry.ToString() + " Line of Command",
                        Time     = GetTimespan(GetActiveDateRange(h, il)),
                        StyleUrl = GetStyle("lineofcommand", 1.0, data.Color)
                    };

                    placemarks.Add(placemark);
                });
            });



            return(placemarks);
        }
Пример #5
0
        string MakeDetailedGeocoderUrl(Placemark placemark)
        {
            var street = String.Join(" ", new[] { placemark.HouseNo, placemark.ThoroughfareName }).Trim();

            return(string.Format(GeocoderDetailedUrlFormat,
                                 street.Replace(' ', '+'),
                                 placemark.LocalityName.Replace(' ', '+'),
                                 placemark.SubAdministrativeAreaName.Replace(' ', '+'),
                                 placemark.AdministrativeAreaName.Replace(' ', '+'),
                                 placemark.CountryName.Replace(' ', '+'),
                                 placemark.PostalCodeNumber.Replace(' ', '+')));
        }
Пример #6
0
        private async Task <string> GetLocationDetails(Location location)
        {
            IEnumerable <Placemark> placemarks = await Geocoding.GetPlacemarksAsync(location);

            Placemark placemark = placemarks.First();

            if (placemark != null && placemark.Locality != null && placemark.CountryName != null)
            {
                return($"{placemark.Locality}, {placemark.CountryName}");
            }

            return(null);
        }
Пример #7
0
        public PointLatLng?GetPoint(Placemark placemark, out GeoCoderStatusCode status)
        {
            List <PointLatLng> points = this.GetPointsByPlacemark(placemark);

            if (points != null && points.Count > 0)
            {
                status = GeoCoderStatusCode.G_GEO_SUCCESS;
                return(points[0]);
            }

            status = GeoCoderStatusCode.Unknow;
            return(null);
        }
Пример #8
0
        private static Vector[] InitializePointCoordinates(Placemark placemark)
        {
            List <Vector> coordinates = new List <Vector>();

            foreach (var point in placemark.Flatten().OfType <Point>())
            {
                Vector myVector = new Vector();
                myVector.Latitude  = point.Coordinate.Latitude;
                myVector.Longitude = point.Coordinate.Longitude;
                coordinates.Add(myVector);
            }
            return(coordinates.ToArray());
        }
Пример #9
0
        [TestCase(-38.15322222222222, 145.31143611111114)] // Melbourne, Casey

        public void FindIntersection(double lat, double lng)
        {
            SharpKml.Dom.Point point = new SharpKml.Dom.Point()
            {
                Coordinate = new SharpKml.Base.Vector(lat, lng)
            };

            DocumentData data      = new DocumentData(@"C:\Development\KML\KML.UnitTests\National Territories v2.0.kml");
            Placemark    placemark = data.Intersects(point);

            Assert.IsNotNull(placemark);
            Console.WriteLine($"town {placemark.Name}");
        }
Пример #10
0
        public async Task OpenMapWithPlacemark(Placemark placemark)
        {
            //こちらでもいいし、
            //var options=new MapLaunchOptions
            //{
            //    Name = "Hello"
            //};

            //await Map.OpenAsync(placemark, options);

            //こちらでもよい。
            await placemark.OpenMapsAsync();
        }
Пример #11
0
 public MapFeature(Placemark placemark, int Id)
 {
     this.placemark = placemark;
     if (placemark.Name != null)
     {
         Name = placemark.Name;
     }
     this.Id      = Id;
     GeometryType = SetGeometryType(placemark);
     InitializeCoordinates(placemark);
     InitializeData(placemark);
     SantizeData();
 }
Пример #12
0
        private static Vector[][] InitializePolygonCoordinates(Placemark placemark)
        {
            List <List <Vector> > coordinates = new List <List <Vector> >();

            coordinates.Add(new List <Vector>());

            foreach (var polygon in placemark.Flatten().OfType <Polygon>())
            {
                coordinates[0].AddRange(polygon.OuterBoundary.LinearRing.Coordinates);
                coordinates.AddRange(polygon.InnerBoundary.Select(inner => inner.LinearRing.Coordinates.ToList()));
            }
            return(coordinates.Select(c => c.ToArray()).ToArray());
        }
Пример #13
0
 public void DisplayCurrentLocationWeatherAsyncTest()
 {
     try
     {
         var       location  = _locationService.Object.GetCurrentLocationAsync();
         Placemark placemark = _locationService.Object.GetCityNameAsync(location);
         Assert.IsNotNull(placemark, "Placemark should not null");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
Пример #14
0
        public override void addAddresstoKmlDocument(KmlPrepData prepData, Document KmlDoc)
        {
            Point point = new Point();

            point.Coordinate = new Vector(prepData.lat, prepData.lng);

            Placemark placemark = new Placemark();

            placemark.Geometry = point;
            placemark.Name     = prepData.name;

            KmlDoc.AddFeature(placemark);
        }
        public void From_Placemark_WithDescriptionAndNameSet_ReturnsTerritoryNoAndCode()
        {
            var placemark = new Placemark()
            {
                description = "test description",
                name        = "test name"
            };

            var territory = PlacemarkConverter.From(placemark);

            Assert.AreEqual("test description", territory.Description);
            Assert.AreEqual("test name", territory.Number);
        }
Пример #16
0
        private static KmlFileWriter GetKmlWriter(string vehicleId, string outputDir)
        {
            var document = new Document();

            document.Name        = string.Format("Vehicle {0} trace", vehicleId);
            document.Description = new Description
            {
                Text = string.Format(
                    "Vehicle {0} trace, starts from {1}",
                    vehicleId,
                    DateTime.Now.ToString("u"))
            };

            var style = new Style
            {
                Id   = "routePathStyle",
                Line = new LineStyle
                {
                    Color = Color32.Parse("7f00ffff"),
                    Width = 4
                }
            };

            document.AddStyle(style);

            var placeMark = new Placemark
            {
                Name     = string.Format("Vehicle {0} path", vehicleId),
                StyleUrl = new Uri("#routePathStyle", UriKind.RelativeOrAbsolute)
            };

            var lineString = new LineString
            {
                Extrude      = true,
                AltitudeMode = AltitudeMode.ClampToGround,
                Coordinates  = new CoordinateCollection(),
                Tessellate   = true
            };

            placeMark.Geometry = lineString;
            document.AddFeature(placeMark);

            var kmlOutputDirectory = new DirectoryInfo(_outputDir).FullName;

            return(new KmlFileWriter
            {
                KmlFile = KmlFile.Create(document, false),
                Path = lineString,
                OutputFile = Path.Combine(kmlOutputDirectory, string.Format("trace-{0}.kml", vehicleId))
            });
        }
 public static Address ToAddress(this Placemark placemark)
 {
     return(new Address(
                placemark.CountryCode,
                placemark.CountryName,
                placemark.PostalCode,
                placemark.AdminArea,
                placemark.SubAdminArea,
                placemark.Locality,
                placemark.SubLocality,
                placemark.Thoroughfare,
                placemark.SubThoroughfare,
                placemark.FeatureName));
 }
Пример #18
0
        private async Task <Placemark> GetZoneOfInfluence(RenderEntry data)
        {
            Polygon polygon = GetInfluencePolygon(data.Entry.Where.Latitude, data.Entry.Where.Longtitude, data.Entry.What.ZoneOfInfluence.Range);

            var placemark = new Placemark
            {
                Geometry = polygon,
                Name     = data.Entry.ToString() + " Zone of Influence",
                Time     = GetTimespan(data.Entry.When),
                StyleUrl = GetStyle("zoneofinfluence", data.Entry.What.ZoneOfInfluence.Density, data.Color)
            };

            return(placemark);
        }
Пример #19
0
        private static List <Placemark> DeserializarPlacemark(XmlDocument xmldoc)
        {
            XmlNodeList      nodeList   = xmldoc.GetElementsByTagName("Placemark");
            List <Placemark> placemarks = new List <Placemark>();

            foreach (XmlNode node in nodeList)
            {
                Placemark placemark = new Placemark();
                placemarks.Add(ConvertNode <Placemark>(node));
            }


            return(placemarks);
        }
Пример #20
0
        private static Vector[][] InitializeLineCoordinates(Placemark placemark)
        {
            List <List <Vector> > coordinates = new List <List <Vector> >();

            int lineStringIndex = 0;

            foreach (LineString lineString in placemark.Flatten().OfType <LineString>())
            {
                coordinates.Add(new List <Vector>());
                coordinates[lineStringIndex].AddRange(lineString.Coordinates);
                lineStringIndex++;
            }
            return(coordinates.Select(c => c.ToArray()).ToArray());
        }
Пример #21
0
 string MakeGeocoderDetailedUrl(Placemark placemark)
 {
     return(string.Format(GeocoderDetailedUrlFormat,
                          PrepareUrlString(placemark.CountryName),
                          PrepareUrlString(placemark.AdministrativeAreaName),
                          PrepareUrlString(placemark.SubAdministrativeAreaName),
                          PrepareUrlString(placemark.LocalityName),
                          PrepareUrlString(placemark.DistrictName),
                          PrepareUrlString(placemark.PostalCodeNumber),
                          PrepareUrlString(placemark.ThoroughfareName),
                          PrepareUrlString(placemark.HouseNo),
                          AppId,
                          !string.IsNullOrEmpty(LanguageStr) ? "&locale=" + LanguageStr : string.Empty));
 }
        public async Task NavigateToBuilding25()
        {
            var placemark = new Placemark
            {
                CountryName  = tara.Text,
                Thoroughfare = adr.Text,
                Locality     = loc.Text
            };
            var options = new MapLaunchOptions {
                NavigationMode = NavigationMode.Driving
            };

            await Map.OpenAsync(placemark, options);
        }
Пример #23
0
        public async Task <bool> TryOpenAsync(Placemark placemark, MapLaunchOptions options)
        {
            if (placemark == null)
            {
                throw new ArgumentNullException(nameof(placemark));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

#if __IOS__
            var address = new MKPlacemarkAddress
            {
                CountryCode = placemark.CountryCode,
                Country     = placemark.CountryName,
                State       = placemark.AdminArea,
                Street      = placemark.Thoroughfare,
                City        = placemark.Locality,
                Zip         = placemark.PostalCode
            }.Dictionary;
#else
            var address = new NSMutableDictionary
            {
                [CNPostalAddressKey.City]           = new NSString(placemark.Locality ?? string.Empty),
                [CNPostalAddressKey.Country]        = new NSString(placemark.CountryName ?? string.Empty),
                [CNPostalAddressKey.State]          = new NSString(placemark.AdminArea ?? string.Empty),
                [CNPostalAddressKey.Street]         = new NSString(placemark.Thoroughfare ?? string.Empty),
                [CNPostalAddressKey.PostalCode]     = new NSString(placemark.PostalCode ?? string.Empty),
                [CNPostalAddressKey.IsoCountryCode] = new NSString(placemark.CountryCode ?? string.Empty)
            };
#endif

            var resolvedPlacemarks = await GetPlacemarksAsync(address);

            if (resolvedPlacemarks?.Length > 0)
            {
                return(await OpenPlacemark(new MKPlacemark(resolvedPlacemarks[0].Location.Coordinate, address), options));
            }
            else
            {
#if __IOS__ || __MACOS__
                // https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
                var uri   = $"http://maps.apple.com/?q={placemark.GetEscapedAddress()}";
                var nsurl = NSUrl.FromString(uri);

                return(await Launcher.Default.TryOpenAsync(nsurl));
#else
                return(await OpenPlacemark(new MKPlacemark(default, address), options));
Пример #24
0
        private async void Find_vej_Clicked(object sender, EventArgs e)
        {
            var Placemark = new Placemark
            {
                Thoroughfare = PlacemarkText.Text
            };
            NavigationMode NavMode = GetNavmode();

            var options = new MapLaunchOptions {
                NavigationMode = NavMode
            };

            await Map.OpenAsync(Placemark, options);
        }
        /// <summary>
        /// Wraps a Google Result into a Placemark
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public static Placemark ToPlacemark(Result result)
        {
            var placemark = new Placemark
            {
                Address          = result.FormattedAddress,
                HouseNo          = FindAddressPart(result.AddressComponents, AddressType.StreetNumber),
                CountryName      = FindAddressPart(result.AddressComponents, AddressType.Country),
                PostalCodeNumber = FindAddressPart(result.AddressComponents, AddressType.PostalCode),
                DistrictName     = FindAddressPart(result.AddressComponents, AddressType.StreetAddress),
                ThoroughfareName = FindAddressPart(result.AddressComponents, AddressType.StreetAddress),
            };

            return(placemark);
        }
Пример #26
0
 private Shift CreateInitShift(Placemark currentLocation, DateTime currentTime)
 {
     return(new Shift()
     {
         DepartureLocation = currentLocation.Locality,
         DepartureTime = currentTime,
         TimeFrom = currentTime,
         TimeTo = currentTime,
         ArrivalTime = currentTime,
         IsClosed = true,
         WithDiets = true,
         IsNightShift = currentTime.Hour > 18
     });
 }
Пример #27
0
        public static void Run()
        {
            Console.WriteLine("Creating a point at 37.42052549 latitude and -122.0816695 longitude.\n");

            // This will be used for the placemark
            var point = new Point
            {
                Coordinate = new Vector(37.42052549, -122.0816695)
            };

            var coordinates = new CoordinateCollection();

            var lineString = new LineString()
            {
                Extrude      = true,
                Tessellate   = true,
                AltitudeMode = AltitudeMode.Absolute,
                Coordinates  = coordinates
            };

            var placemark = new Placemark
            {
                Name     = "Cool Statue",
                Geometry = lineString
            };

            // This is the root element of the file
            var kml = new Kml
            {
                Feature = placemark
            };

            var serializer = new Serializer();

            serializer.Serialize(kml);
            Console.WriteLine(serializer.Xml);

            Console.WriteLine("\nReading Xml...");

            var parser = new Parser();

            parser.ParseString(serializer.Xml, true);

            kml       = (Kml)parser.Root;
            placemark = (Placemark)kml.Feature;
            point     = (Point)placemark.Geometry;

            Console.WriteLine("Latitude:{0} Longitude:{1}", point.Coordinate.Latitude, point.Coordinate.Longitude);
        }
Пример #28
0
        async void MapwithPlacemark()
        {
            var placemark = new Placemark
            {
                CountryName  = "United States",
                AdminArea    = "WA",
                Thoroughfare = "Microsoft Building 25",
                Locality     = "Redmond"
            };
            var options = new MapLaunchOptions {
                Name = "Microsoft Building 25"
            };

            await Map.OpenAsync(placemark, options);
        }
Пример #29
0
        /// <summary>
        /// Returns sanitized description HTML text from given placemark.
        /// </summary>
        /// <param name="placemark">placemark to use</param>
        /// <returns>HTML description text</returns>
        private static string GetDescriptionFromPlacemark(Placemark placemark)
        {
            string text = placemark.Description?.Text ?? string.Empty;

            // no HTML tags? assume MarkDown
            if (!text.Contains("<") &&
                !text.Contains(">"))
            {
                text = HtmlConverter.FromMarkdown(text);
            }

            text = HtmlConverter.Sanitize(text);

            return(text);
        }
        private async Task SaveLocationAndPlacemark(Location location, Placemark placemark)
        {
            var loc = new LocationModel()
            {
                Latitude    = location.Latitude,
                Longitude   = location.Longitude,
                Locality    = placemark.Locality,
                CountryName = placemark.CountryName,
                Selected    = true
            };
            var listLoc = new List <LocationModel>();

            listLoc.Add(loc);
            await SecureStorage.SetAsync("locations", JsonConvert.SerializeObject(listLoc));
        }
Пример #31
0
 public static double CalculateQiblah(GeoCoder g, Placemark p)
 {
     double result = double.NaN;
     if (g.StatusCode != GeoErrors.G_GEO_SUCCESS)
     {
         throw new ApplicationException("Cannot located Qiblah for your location.");
     }
     else
     {
         DotFermion.Qiblah.QiblahCalculator calc =
             new DotFermion.Qiblah.QiblahCalculator(p.Latitude,
                 p.Longitude);
         result = calc.Qiblah;
     }
     return result;
 }
Пример #32
0
        public static Document GenerateKML(List<Segment> segments)
        {
            Document d = new Document();
            d.Style = new List<Style>();
            Style st = new Style();
            st.Id = "yellowLine";
            st.LineStyle = new LineStyle();
            st.LineStyle.Color = "7f00ffff";
            st.LineStyle.Width = "4";
            d.Style.Add(st);
            st = new Style();
            st.Id = "greenLine";
            st.LineStyle = new LineStyle();
            st.LineStyle.Color = "7d00ff00";
            st.LineStyle.Width = "4";
            d.Style.Add(st);
            st = new Style();
            st.Id = "redLine";
            st.LineStyle = new LineStyle();
            st.LineStyle.Color = "ff0000ff";
            st.LineStyle.Width = "4";
            d.Style.Add(st);
            st = new Style();
            st.Id = "blueLine";
            st.LineStyle = new LineStyle();
            st.LineStyle.Color = "ffff0000";
            st.LineStyle.Width = "4";
            d.Style.Add(st);
            st = new Style();
            st.Id = "blackLine";
            st.LineStyle = new LineStyle();
            st.LineStyle.Color = "87000000";
            st.LineStyle.Width = "4";
            d.Style.Add(st);

            completeSegments.AddRange(segments);

            d.Placemarks = new List<Placemark>();

            for (int i = 0; i < segments.Count; i++)
            {
                Segment item = segments[i];
                Placemark p = new Placemark();
                p.Name = string.Format("{0},{1},{2},{3},{4}",item.AvgDevYaw.ToString("#.###"),item.AvgDevRoll.ToString("#.###"),item.AvgDevPitch.ToString("#.###"),item.Speed.ToString(),item.RoadCondition.ToString());
                p.Description = "JK";
                p.LineString = new LineString();
                p.LineString.AltitudeMode = "absolute";
                p.LineString.Coordinates = string.Format("{0},{1},0,{2},{3},0", item.StartLog,item.StartLat , item.EndLog, item.EndLat );
                p.StyleUrl = GetRoadConditionStyleID(item.RoadCondition);
                d.Placemarks.Add(p);
            }

            return d;
        }
      GeoCoderStatusCode GetLatLngFromGeocoderUrl(string url, out List<PointLatLng> pointList)
      {
         var status = GeoCoderStatusCode.Unknow;
         pointList = null;

         try
         {
            string geo = GMaps.Instance.UseGeocoderCache ? Cache.Instance.GetContent(url, CacheType.GeocoderCache) : string.Empty;

            bool cache = false;

            if(string.IsNullOrEmpty(geo))
            {
               geo = GetContentUsingHttp(url);

               if(!string.IsNullOrEmpty(geo))
               {
                  cache = true;
               }
            }

            if(!string.IsNullOrEmpty(geo))
            {
               if(geo.StartsWith("<?xml") && geo.Contains("<place"))
               {
                  if(cache && GMaps.Instance.UseGeocoderCache)
                  {
                     Cache.Instance.SaveContent(url, CacheType.GeocoderCache, geo);
                  }

                  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(geo);
                  {
                     XmlNodeList l = doc.SelectNodes("/searchresults/place");
                     if(l != null)
                     {
                        pointList = new List<PointLatLng>();

                        foreach(XmlNode n in l)
                        {
                           var nn = n.Attributes["place_rank"];

                           int rank = 0;
#if !PocketPC
                           if (nn != null && Int32.TryParse(nn.Value, out rank))
                           {
#else
                           if(nn != null && !string.IsNullOrEmpty(nn.Value))
                           {
                              rank = int.Parse(nn.Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
#endif
                              if(rank < MinExpectedRank)
                                 continue;
                           }

                           nn = n.Attributes["lat"];
                           if(nn != null)
                           {
                              double lat = double.Parse(nn.Value, CultureInfo.InvariantCulture);

                              nn = n.Attributes["lon"];
                              if(nn != null)
                              {
                                 double lng = double.Parse(nn.Value, CultureInfo.InvariantCulture);
                                 pointList.Add(new PointLatLng(lat, lng));
                              }
                           }
                        }

                        status = GeoCoderStatusCode.G_GEO_SUCCESS;
                     }
                  }
               }
            }
         }
         catch(Exception ex)
         {
            status = GeoCoderStatusCode.ExceptionInCode;
            Debug.WriteLine("GetLatLngFromGeocoderUrl: " + ex);
         }

         return status;
      }

      Placemark? GetPlacemarkFromReverseGeocoderUrl(string url, out GeoCoderStatusCode status)
      {
         status = GeoCoderStatusCode.Unknow;
         Placemark? ret = null;

         try
         {
            string geo = GMaps.Instance.UsePlacemarkCache ? Cache.Instance.GetContent(url, CacheType.PlacemarkCache) : string.Empty;

            bool cache = false;

            if(string.IsNullOrEmpty(geo))
            {
               geo = GetContentUsingHttp(url);

               if(!string.IsNullOrEmpty(geo))
               {
                  cache = true;
               }
            }

            if(!string.IsNullOrEmpty(geo))
            {
               if(geo.StartsWith("<?xml") && geo.Contains("<result"))
               {
                  if(cache && GMaps.Instance.UsePlacemarkCache)
                  {
                     Cache.Instance.SaveContent(url, CacheType.PlacemarkCache, geo);
                  }

                  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(geo);
                  {
                     XmlNode r = doc.SelectSingleNode("/reversegeocode/result");
                     if(r != null)
                     {
                        var p = new Placemark(r.InnerText);

                        XmlNode ad = doc.SelectSingleNode("/reversegeocode/addressparts");
                        if(ad != null)
                        {
                           var vl = ad.SelectSingleNode("country");
                           if(vl != null)
                           {
                              p.CountryName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("country_code");
                           if(vl != null)
                           {
                              p.CountryNameCode = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("postcode");
                           if(vl != null)
                           {
                              p.PostalCodeNumber = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("state");
                           if(vl != null)
                           {
                              p.AdministrativeAreaName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("region");
                           if(vl != null)
                           {
                              p.SubAdministrativeAreaName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("suburb");
                           if(vl != null)
                           {
                              p.LocalityName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("road");
                           if(vl != null)
                           {
                              p.ThoroughfareName = vl.InnerText;
                           }
                        }

                        ret = p;

                        status = GeoCoderStatusCode.G_GEO_SUCCESS;
                     }
                  }
               }
            }
         }
         catch(Exception ex)
         {
            ret = null;
            status = GeoCoderStatusCode.ExceptionInCode;
            Debug.WriteLine("GetPlacemarkFromReverseGeocoderUrl: " + ex);
         }

         return ret;
      }
Пример #34
0
        public GeoCoderStatusCode GetPoints(Placemark placemark, out List<PointLatLng> pointList)
        {
            // http://nominatim.openstreetmap.org/search?street=&city=vilnius&county=&state=&country=lithuania&postalcode=&format=xml

              #region -- response --
              //<searchresults timestamp="Thu, 29 Nov 12 08:38:23 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="vilnius, lithuania" polygon="false" exclude_place_ids="98093941" more_url="http://nominatim.openstreetmap.org/search?format=xml&exclude_place_ids=98093941&accept-language=de-de,de;q=0.8,en-us;q=0.5,en;q=0.3&q=vilnius%2C+lithuania">
              //<place place_id="98093941" osm_type="relation" osm_id="1529146" place_rank="16" boundingbox="54.5693359375,54.8323097229004,25.0250644683838,25.4815216064453" lat="54.6843135" lon="25.2853984" display_name="Vilnius, Vilniaus m. savivaldybė, Distrikt Vilnius, Litauen" class="boundary" type="administrative" icon="http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png"/>
              //</searchresults>
              #endregion

              return GetLatLngFromGeocoderUrl(MakeDetailedGeocoderUrl(placemark), out pointList);
        }
Пример #35
0
        GeoCoderStatusCode GetPlacemarkFromReverseGeocoderUrl(string url, out List<Placemark> placemarkList)
        {
            GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;
             placemarkList = null;

             try
             {
            string urlEnd = url.Substring(url.IndexOf("geo?hl="));

            string reverse = GMaps.Instance.UsePlacemarkCache ? Cache.Instance.GetContent(urlEnd, CacheType.PlacemarkCache) : string.Empty;

            bool cache = false;

            if(string.IsNullOrEmpty(reverse))
            {
               reverse = GetContentUsingHttp(url);

               if(!string.IsNullOrEmpty(reverse))
               {
                  cache = true;
               }
            }

            if(!string.IsNullOrEmpty(reverse))
            {
               if(reverse.StartsWith("200"))
               {
                  if(cache && GMaps.Instance.UsePlacemarkCache)
                  {
                     Cache.Instance.SaveContent(urlEnd, CacheType.PlacemarkCache, reverse);
                  }

                  string acc = reverse.Substring(0, reverse.IndexOf('\"'));
                  var ret = new Placemark(reverse.Substring(reverse.IndexOf('\"')));
                  ret.Accuracy = int.Parse(acc.Split(',').GetValue(1) as string);
                  placemarkList = new List<Placemark>();
                  placemarkList.Add(ret);
                  status = GeoCoderStatusCode.G_GEO_SUCCESS;
               }
               else if(reverse.StartsWith("<?xml"))
               {
                  #region -- kml version --

                  #region -- kml response --
                  //<?xml version="1.0" encoding="UTF-8" ?>
                  //<kml xmlns="http://earth.server.com/kml/2.0">
                  // <Response>
                  //  <name>55.023322,24.668408</name>
                  //  <Status>
                  //    <code>200</code>
                  //    <request>geocode</request>
                  //  </Status>

                  //  <Placemark id="p1">
                  //    <address>4313, Širvintos 19023, Lithuania</address>
                  //    <AddressDetails Accuracy="6" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName><Thoroughfare><ThoroughfareName>4313</ThoroughfareName></Thoroughfare><PostalCode><PostalCodeNumber>19023</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></Country></AddressDetails>
                  //    <ExtendedData>
                  //      <LatLonBox north="55.0270661" south="55.0207709" east="24.6711965" west="24.6573382" />
                  //    </ExtendedData>
                  //    <Point><coordinates>24.6642677,55.0239187,0</coordinates></Point>
                  //  </Placemark>

                  //  <Placemark id="p2">
                  //    <address>Širvintos 19023, Lithuania</address>
                  //    <AddressDetails Accuracy="5" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName><PostalCode><PostalCodeNumber>19023</PostalCodeNumber></PostalCode></Locality></SubAdministrativeArea></Country></AddressDetails>
                  //    <ExtendedData>
                  //      <LatLonBox north="55.1109513" south="54.9867479" east="24.7563286" west="24.5854650" />
                  //    </ExtendedData>
                  //    <Point><coordinates>24.6778290,55.0561428,0</coordinates></Point>
                  //  </Placemark>

                  //  <Placemark id="p3">
                  //    <address>Širvintos, Lithuania</address>
                  //    <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName><Locality><LocalityName>Širvintos</LocalityName></Locality></SubAdministrativeArea></Country></AddressDetails>
                  //    <ExtendedData>
                  //      <LatLonBox north="55.1597127" south="54.8595715" east="25.2358124" west="24.5536348" />
                  //    </ExtendedData>
                  //    <Point><coordinates>24.9447696,55.0482439,0</coordinates></Point>
                  //  </Placemark>

                  //  <Placemark id="p4">
                  //    <address>Vilnius Region, Lithuania</address>
                  //    <AddressDetails Accuracy="3" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName><SubAdministrativeArea><SubAdministrativeAreaName>Vilnius Region</SubAdministrativeAreaName></SubAdministrativeArea></Country></AddressDetails>
                  //    <ExtendedData>
                  //      <LatLonBox north="55.5177330" south="54.1276791" east="26.7590747" west="24.3866334" />
                  //    </ExtendedData>
                  //    <Point><coordinates>25.2182138,54.8086502,0</coordinates></Point>
                  //  </Placemark>

                  //  <Placemark id="p5">
                  //    <address>Lithuania</address>
                  //    <AddressDetails Accuracy="1" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>LT</CountryNameCode><CountryName>Lithuania</CountryName></Country></AddressDetails>
                  //    <ExtendedData>
                  //      <LatLonBox north="56.4503174" south="53.8986720" east="26.8356500" west="20.9310000" />
                  //    </ExtendedData>
                  //    <Point><coordinates>23.8812750,55.1694380,0</coordinates></Point>
                  //  </Placemark>
                  //</Response>
                  //</kml>
                  #endregion

                  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(reverse);

                  XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
                  nsMgr.AddNamespace("sm", string.Format("http://earth.{0}/kml/2.0", Server));
                  nsMgr.AddNamespace("sn", "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0");

                  var codeNode = doc.SelectSingleNode("//sm:Status/sm:code", nsMgr);
                  if(codeNode != null)
                  {
                     status = (GeoCoderStatusCode)int.Parse(codeNode.InnerText);
                     if(status == GeoCoderStatusCode.G_GEO_SUCCESS)
                     {
                        if(cache && GMaps.Instance.UsePlacemarkCache)
                        {
                           Cache.Instance.SaveContent(urlEnd, CacheType.PlacemarkCache, reverse);
                        }

                        placemarkList = new List<Placemark>();

                        #region -- placemarks --
                        XmlNodeList l = doc.SelectNodes("/sm:kml/sm:Response/sm:Placemark", nsMgr);
                        if(l != null)
                        {
                           foreach(XmlNode n in l)
                           {
                              XmlNode nnd, nnl, nn;
                              {
                                 nn = n.SelectSingleNode("sm:address", nsMgr);
                                 if(nn != null)
                                 {
                                    var ret = new Placemark(nn.InnerText);

                                    nnd = n.SelectSingleNode("sn:AddressDetails", nsMgr);
                                    if(nnd != null)
                                    {
                                       nn = nnd.SelectSingleNode("@Accuracy", nsMgr);
                                       if(nn != null)
                                       {
                                          ret.Accuracy = int.Parse(nn.InnerText);
                                       }

                                       nn = nnd.SelectSingleNode("sn:Country/sn:CountryNameCode", nsMgr);
                                       if(nn != null)
                                       {
                                          ret.CountryNameCode = nn.InnerText;
                                       }

                                       nn = nnd.SelectSingleNode("sn:Country/sn:CountryName", nsMgr);
                                       if(nn != null)
                                       {
                                          ret.CountryName = nn.InnerText;
                                       }

                                       nn = nnd.SelectSingleNode("descendant::sn:AdministrativeArea/sn:AdministrativeAreaName", nsMgr);
                                       if(nn != null)
                                       {
                                          ret.AdministrativeAreaName = nn.InnerText;
                                       }

                                       nn = nnd.SelectSingleNode("descendant::sn:SubAdministrativeArea/sn:SubAdministrativeAreaName", nsMgr);
                                       if(nn != null)
                                       {
                                          ret.SubAdministrativeAreaName = nn.InnerText;
                                       }

                                       // Locality or DependentLocality tag ?
                                       nnl = nnd.SelectSingleNode("descendant::sn:Locality", nsMgr) ?? nnd.SelectSingleNode("descendant::sn:DependentLocality", nsMgr);
                                       if(nnl != null)
                                       {
                                          nn = nnl.SelectSingleNode(string.Format("sn:{0}Name", nnl.Name), nsMgr);
                                          if(nn != null)
                                          {
                                             ret.LocalityName = nn.InnerText;
                                          }

                                          nn = nnl.SelectSingleNode("sn:Thoroughfare/sn:ThoroughfareName", nsMgr);
                                          if(nn != null)
                                          {
                                             ret.ThoroughfareName = nn.InnerText;
                                          }

                                          nn = nnl.SelectSingleNode("sn:PostalCode/sn:PostalCodeNumber", nsMgr);
                                          if(nn != null)
                                          {
                                             ret.PostalCodeNumber = nn.InnerText;
                                          }
                                       }
                                    }

                                    placemarkList.Add(ret);
                                 }
                              }
                           }
                        }
                        #endregion
                     }
                  }
                  #endregion
               }
            }
             }
             catch(Exception ex)
             {
            status = GeoCoderStatusCode.ExceptionInCode;
            placemarkList = null;
            Debug.WriteLine("GetPlacemarkReverseGeocoderUrl: " + ex.ToString());
             }

             return status;
        }
Пример #36
0
 public PointLatLng? GetPoint(Placemark placemark, out GeoCoderStatusCode status)
 {
     List<PointLatLng> pointList;
     status = GetPoints(placemark, out pointList);
     return pointList != null && pointList.Count > 0 ? pointList[0] : (PointLatLng?)null;
 }
Пример #37
0
        string MakeGeocoderDetailedUrl(Placemark placemark)
        {
            string parameters = string.Empty;

             if(!AddFieldIfNotEmpty(ref parameters, "countryRegion", placemark.CountryNameCode))
            AddFieldIfNotEmpty(ref parameters, "countryRegion", placemark.CountryName);

             AddFieldIfNotEmpty(ref parameters, "adminDistrict", placemark.DistrictName);
             AddFieldIfNotEmpty(ref parameters, "locality", placemark.LocalityName);
             AddFieldIfNotEmpty(ref parameters, "postalCode", placemark.PostalCodeNumber);

             if(!string.IsNullOrEmpty(placemark.HouseNo))
            AddFieldIfNotEmpty(ref parameters, "addressLine", placemark.ThoroughfareName + " " + placemark.HouseNo);
             else
            AddFieldIfNotEmpty(ref parameters, "addressLine", placemark.ThoroughfareName);

             return MakeGeocoderUrl(parameters);
        }
Пример #38
0
        GeoCoderStatusCode GetPlacemarkFromReverseGeocoderUrl(string url, out List<Placemark> placemarkList)
        {
            GeoCoderStatusCode status = GeoCoderStatusCode.Unknow;
            placemarkList = null;

            try
            {
                string reverse = GMaps.Instance.UsePlacemarkCache ? Cache.Instance.GetContent(url, CacheType.PlacemarkCache) : string.Empty;

                bool cache = false;

                if (string.IsNullOrEmpty(reverse))
                {
                    reverse = GetContentUsingHttp(url);

                    if (!string.IsNullOrEmpty(reverse))
                    {
                        cache = true;
                    }
                }

                if (!string.IsNullOrEmpty(reverse))
                {
                    if (reverse.StartsWith("<?xml"))
                    {
                        #region -- xml response --
                        //<?xml version="1.0" encoding="UTF-8"?>
                        //<GeocodeResponse>
                        // <status>OK</status>
                        // <result>
                        //  <type>street_address</type>
                        //  <formatted_address>Tuskul??n?? gatv?? 2, Vilnius 09213, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>2</long_name>
                        //   <short_name>2</short_name>
                        //   <type>street_number</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Tuskul??n?? gatv??</long_name>
                        //   <short_name>Tuskul??n?? g.</short_name>
                        //   <type>route</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius</long_name>
                        //   <short_name>Vilnius</short_name>
                        //   <type>locality</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>09213</long_name>
                        //   <short_name>09213</short_name>
                        //   <type>postal_code</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.6963339</lat>
                        //    <lng>25.2968939</lng>
                        //   </location>
                        //   <location_type>ROOFTOP</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.6949849</lat>
                        //     <lng>25.2955449</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.6976829</lat>
                        //     <lng>25.2982429</lng>
                        //    </northeast>
                        //   </viewport>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>postal_code</type>
                        //  <formatted_address>Vilnius 09213, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>09213</long_name>
                        //   <short_name>09213</short_name>
                        //   <type>postal_code</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius</long_name>
                        //   <short_name>Vilnius</short_name>
                        //   <type>locality</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.6963032</lat>
                        //    <lng>25.2967390</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.6950889</lat>
                        //     <lng>25.2958851</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.6977869</lat>
                        //     <lng>25.2985830</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.6956179</lat>
                        //     <lng>25.2958871</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.6972579</lat>
                        //     <lng>25.2985810</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>neighborhood</type>
                        //  <type>political</type>
                        //  <formatted_address>??irm??nai, Vilnius, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>??irm??nai</long_name>
                        //   <short_name>??irm??nai</short_name>
                        //   <type>neighborhood</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius</long_name>
                        //   <short_name>Vilnius</short_name>
                        //   <type>locality</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.7117424</lat>
                        //    <lng>25.2974345</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.6888939</lat>
                        //     <lng>25.2838700</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.7304441</lat>
                        //     <lng>25.3133630</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.6888939</lat>
                        //     <lng>25.2838700</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.7304441</lat>
                        //     <lng>25.3133630</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>administrative_area_level_3</type>
                        //  <type>political</type>
                        //  <formatted_address>??irm??n?? seni??nija, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>??irm??n?? seni??nija</long_name>
                        //   <short_name>??irm??n?? sen.</short_name>
                        //   <type>administrative_area_level_3</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.7117424</lat>
                        //    <lng>25.2974345</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.6892135</lat>
                        //     <lng>25.2837150</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.7305878</lat>
                        //     <lng>25.3135630</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.6892135</lat>
                        //     <lng>25.2837150</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.7305878</lat>
                        //     <lng>25.3135630</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>locality</type>
                        //  <type>political</type>
                        //  <formatted_address>Vilnius, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>Vilnius</long_name>
                        //   <short_name>Vilnius</short_name>
                        //   <type>locality</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.6871555</lat>
                        //    <lng>25.2796514</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.5677980</lat>
                        //     <lng>25.0243760</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.8325440</lat>
                        //     <lng>25.4814883</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.5677980</lat>
                        //     <lng>25.0243760</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.8325440</lat>
                        //     <lng>25.4814883</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>administrative_area_level_2</type>
                        //  <type>political</type>
                        //  <formatted_address>Vilniaus miesto savivaldyb??, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>Vilniaus miesto savivaldyb??</long_name>
                        //   <short_name>Vilniaus m. sav.</short_name>
                        //   <type>administrative_area_level_2</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.6759715</lat>
                        //    <lng>25.2867413</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.5677980</lat>
                        //     <lng>25.0243760</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.8325440</lat>
                        //     <lng>25.4814883</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.5677980</lat>
                        //     <lng>25.0243760</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>54.8325440</lat>
                        //     <lng>25.4814883</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>administrative_area_level_1</type>
                        //  <type>political</type>
                        //  <formatted_address>Vilnius County, Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>Vilnius County</long_name>
                        //   <short_name>Vilnius County</short_name>
                        //   <type>administrative_area_level_1</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>54.8086502</lat>
                        //    <lng>25.2182138</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>54.1276599</lat>
                        //     <lng>24.3863751</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>55.5174369</lat>
                        //     <lng>26.7602130</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>54.1276599</lat>
                        //     <lng>24.3863751</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>55.5174369</lat>
                        //     <lng>26.7602130</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        // <result>
                        //  <type>country</type>
                        //  <type>political</type>
                        //  <formatted_address>Lithuania</formatted_address>
                        //  <address_component>
                        //   <long_name>Lithuania</long_name>
                        //   <short_name>LT</short_name>
                        //   <type>country</type>
                        //   <type>political</type>
                        //  </address_component>
                        //  <geometry>
                        //   <location>
                        //    <lat>55.1694380</lat>
                        //    <lng>23.8812750</lng>
                        //   </location>
                        //   <location_type>APPROXIMATE</location_type>
                        //   <viewport>
                        //    <southwest>
                        //     <lat>53.8968787</lat>
                        //     <lng>20.9543679</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>56.4503209</lat>
                        //     <lng>26.8355913</lng>
                        //    </northeast>
                        //   </viewport>
                        //   <bounds>
                        //    <southwest>
                        //     <lat>53.8968787</lat>
                        //     <lng>20.9543679</lng>
                        //    </southwest>
                        //    <northeast>
                        //     <lat>56.4503209</lat>
                        //     <lng>26.8355913</lng>
                        //    </northeast>
                        //   </bounds>
                        //  </geometry>
                        // </result>
                        //</GeocodeResponse>

                        #endregion

                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(reverse);

                        XmlNode nn = doc.SelectSingleNode("//status");
                        if (nn != null)
                        {
                            if (nn.InnerText != "OK")
                            {
                                Debug.WriteLine("GetPlacemarkFromReverseGeocoderUrl: " + nn.InnerText);
                            }
                            else
                            {
                                status = GeoCoderStatusCode.G_GEO_SUCCESS;

                                if (cache && GMaps.Instance.UsePlacemarkCache)
                                {
                                    Cache.Instance.SaveContent(url, CacheType.PlacemarkCache, reverse);
                                }

                                placemarkList = new List<Placemark>();

                                #region -- placemarks --
                                XmlNodeList l = doc.SelectNodes("//result");
                                if (l != null)
                                {
                                    foreach (XmlNode n in l)
                                    {
                                        Debug.WriteLine("---------------------");

                                        nn = n.SelectSingleNode("formatted_address");
                                        if (nn != null)
                                        {
                                            var ret = new Placemark(nn.InnerText);

                                            Debug.WriteLine("formatted_address: [" + nn.InnerText + "]");

                                            nn = n.SelectSingleNode("type");
                                            if (nn != null)
                                            {
                                                Debug.WriteLine("type: " + nn.InnerText);
                                            }

                                            // TODO: fill Placemark details

                                            XmlNodeList acl = n.SelectNodes("address_component");
                                            foreach (XmlNode ac in acl)
                                            {
                                                nn = ac.SelectSingleNode("type");
                                                if (nn != null)
                                                {
                                                    var type = nn.InnerText;
                                                    Debug.Write(" - [" + type + "], ");

                                                    nn = ac.SelectSingleNode("long_name");
                                                    if (nn != null)
                                                    {
                                                        Debug.WriteLine("long_name: [" + nn.InnerText + "]");

                                                        switch (type)
                                                        {
                                                            case "street_address":
                                                            {
                                                                ret.StreetNumber = nn.InnerText;
                                                            }
                                                            break;

                                                            case "route":
                                                            {
                                                                ret.ThoroughfareName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "postal_code":
                                                            {
                                                                ret.PostalCodeNumber = nn.InnerText;
                                                            }
                                                            break;

                                                            case "country":
                                                            {
                                                                ret.CountryName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "locality":
                                                            {
                                                                ret.LocalityName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "administrative_area_level_2":
                                                            {
                                                              ret.DistrictName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "administrative_area_level_1":
                                                            {
                                                                ret.AdministrativeAreaName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "administrative_area_level_3":
                                                            {
                                                                ret.SubAdministrativeAreaName = nn.InnerText;
                                                            }
                                                            break;

                                                            case "neighborhood":
                                                            {
                                                                ret.Neighborhood = nn.InnerText;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            }                                            

                                            placemarkList.Add(ret);
                                        }
                                    }
                                }
                                #endregion
                            }
                        }
        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                status = GeoCoderStatusCode.ExceptionInCode;
                placemarkList = null;
                Debug.WriteLine("GetPlacemarkReverseGeocoderUrl: " + ex.ToString());
            }

            return status;
        }
Пример #39
0
 string MakeGeocoderDetailedUrl(Placemark placemark)
 {
     return string.Format(GeocoderDetailedUrlFormat,
                          PrepareUrlString(placemark.CountryName),
                          PrepareUrlString(placemark.AdministrativeAreaName),
                          PrepareUrlString(placemark.SubAdministrativeAreaName),
                          PrepareUrlString(placemark.LocalityName),
                          PrepareUrlString(placemark.DistrictName),
                          PrepareUrlString(placemark.PostalCodeNumber),
                          PrepareUrlString(placemark.ThoroughfareName),
                          PrepareUrlString(placemark.HouseNo),
                          AppId,
                          !string.IsNullOrEmpty(LanguageStr) ? "&locale=" + LanguageStr : string.Empty);
 }
Пример #40
0
 string MakeDetailedGeocoderUrl(Placemark placemark)
 {
     var street = String.Join(" ", new[] {placemark.HouseNo, placemark.ThoroughfareName}).Trim();
      return string.Format(GeocoderDetailedUrlFormat,
                       street.Replace(' ', '+'),
                       placemark.LocalityName.Replace(' ', '+'),
                       placemark.SubAdministrativeAreaName.Replace(' ', '+'),
                       placemark.AdministrativeAreaName.Replace(' ', '+'),
                       placemark.CountryName.Replace(' ', '+'),
                       placemark.PostalCodeNumber.Replace(' ', '+'));
 }
Пример #41
0
        private static Folder BuildTripTrack(IEnumerable<Pushpin> positions)
        {
            Folder tripTrack = new Folder()
            {
                id = Guid.NewGuid().ToString(),
                name = "Trip Track",
                visibility = true,
                open = true,
                description = "Trip Track"
            };

            StringBuilder linestringBuilder = new StringBuilder(1024);
            var previousPosition = positions.FirstOrDefault();
            foreach (var position in positions.Skip(1))
            {
                linestringBuilder.AppendFormat(
                    "{0},{1},0,{2},{3},0\n",
                    previousPosition.Longitude,
                    previousPosition.Latitude,
                    position.Longitude,
                    position.Latitude);
                previousPosition = position;
            }

            Placemark track = new Placemark()
            {
                name = "TripTrack"
            };
            LineString lineString = new LineString(new coordinates(linestringBuilder.ToString()));
            lineString.tessellate = true;
            track.Geometry = lineString;
            tripTrack.Features.Add(track);

            return tripTrack;
        }
Пример #42
0
 public PointLatLng? GetPoint(Placemark placemark, out GeoCoderStatusCode status)
 {
     List<PointLatLng> pointList;
      status = GetLatLngFromGeocoderUrl(MakeGeocoderDetailedUrl(placemark), out pointList);
      return pointList != null && pointList.Count > 0 ? pointList[0] : (PointLatLng?)null;
 }
Пример #43
0
 /// <summary>
 /// NotImplemented
 /// </summary>
 /// <param name="placemark"></param>
 /// <param name="pointList"></param>
 /// <returns></returns>
 public GeoCoderStatusCode GetPoints(Placemark placemark, out List<PointLatLng> pointList)
 {
     throw new NotImplementedException("use GetPoints(string keywords...");
 }
Пример #44
0
      GeoCoderStatusCode GetPlacemarksFromReverseGeocoderUrl(string url, out List<Placemark> placemarkList)
      {
          var status = GeoCoderStatusCode.Unknow;
          placemarkList = null;

          try
          {
              string geo = GMaps.Instance.UsePlacemarkCache ? Cache.Instance.GetContent(url, CacheType.PlacemarkCache) : string.Empty;

              bool cache = false;

              if (string.IsNullOrEmpty(geo))
              {
                  geo = GetContentUsingHttp(url);

                  if (!string.IsNullOrEmpty(geo))
                  {
                      cache = true;
                  }
              }

              if (!string.IsNullOrEmpty(geo))
              {
                  if (geo.StartsWith("<?xml") && geo.Contains("<ResultSet"))
                  {
                      if (cache && GMaps.Instance.UsePlacemarkCache)
                      {
                          Cache.Instance.SaveContent(url, CacheType.PlacemarkCache, geo);
                      }

                      XmlDocument doc = new XmlDocument();
                      doc.LoadXml(geo);
                      {
                          XmlNodeList l = doc.SelectNodes("/ResultSet/Result");
                          if (l != null)
                          {
                              placemarkList = new List<Placemark>();

                              foreach (XmlNode n in l)
                              {
                                  var vl = n.SelectSingleNode("name");
                                  if (vl == null) continue;

                                  Placemark placemark = new Placemark(vl.InnerText);

                                  vl = n.SelectSingleNode("level0");
                                  if (vl != null)
                                  {
                                      placemark.CountryName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("level0code");
                                  if (vl != null)
                                  {
                                      placemark.CountryNameCode = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("postal");
                                  if (vl != null)
                                  {
                                      placemark.PostalCodeNumber = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("level1");
                                  if (vl != null)
                                  {
                                      placemark.AdministrativeAreaName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("level2");
                                  if (vl != null)
                                  {
                                      placemark.SubAdministrativeAreaName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("level3");
                                  if (vl != null)
                                  {
                                      placemark.LocalityName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("level4");
                                  if (vl != null)
                                  {
                                      placemark.DistrictName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("street");
                                  if (vl != null)
                                  {
                                      placemark.ThoroughfareName = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("house");
                                  if (vl != null)
                                  {
                                      placemark.HouseNo = vl.InnerText;
                                  }

                                  vl = n.SelectSingleNode("radius");
                                  if (vl != null)
                                  {
                                      placemark.Accuracy = int.Parse(vl.InnerText);
                                  }
                                  
                                  placemarkList.Add(placemark);
                              }

                              status = GeoCoderStatusCode.G_GEO_SUCCESS;
                          }
                      }
                  }
              }
          }
          catch (Exception ex)
          {
              status = GeoCoderStatusCode.ExceptionInCode;
              Debug.WriteLine("GetPlacemarkFromReverseGeocoderUrl: " + ex);
          }

          return status;
      }
Пример #45
0
 /// <summary>
 /// NotImplemented
 /// </summary>
 /// <param name="placemark"></param>
 /// <param name="status"></param>
 /// <returns></returns>
 public PointLatLng? GetPoint(Placemark placemark, out GeoCoderStatusCode status)
 {
     throw new NotImplementedException("use GetPoint(string keywords...");
 }
Пример #46
0
      public GeoCoderStatusCode GetPoints(Placemark placemark, out List<PointLatLng> pointList)
      {
          // http://where.yahooapis.com/geocode?country=LT&state=Vilniaus+Apskritis&county=Vilniaus+Miesto+Savivaldybe&city=Vilnius&neighborhood=Naujamiestis&postal=01108&street=J.+Tumo-Vaizganto+Gatve&house=2&appid=1234&flags=CG&gflags=QL&locale=LT-lt

          #region -- response --
          //<ResultSet version="1.0"><Error>0</Error><ErrorMessage>No error</ErrorMessage><Locale>LT-lt</Locale><Quality>19</Quality><Found>1</Found><Result><quality>87</quality><latitude>54.690181</latitude><longitude>25.269483</longitude><offsetlat>54.690227</offsetlat><offsetlon>25.269278</offsetlon><radius>500</radius></Result></ResultSet>
          #endregion

          return GetLatLngFromGeocoderUrl(MakeGeocoderDetailedUrl(placemark), out pointList);
      }
        Placemark GetPlacemarkFromReverseGeocoderUrl(string url, out GeoCoderStatusCode status)
        {
            status = GeoCoderStatusCode.Unknow;
             Placemark ret = null;

             try
             {
            string geo = GMaps.Instance.UsePlacemarkCache ? Cache.Instance.GetContent(url, CacheType.PlacemarkCache) : string.Empty;

            bool cache = false;

            if(string.IsNullOrEmpty(geo))
            {
               geo = GetContentUsingHttp(url);

               if(!string.IsNullOrEmpty(geo))
               {
                  cache = true;
               }
            }

            if(!string.IsNullOrEmpty(geo))
            {
               if(geo.StartsWith("<?xml") && geo.Contains("<result"))
               {
                  if(cache && GMaps.Instance.UsePlacemarkCache)
                  {
                     Cache.Instance.SaveContent(url, CacheType.PlacemarkCache, geo);
                  }

                  XmlDocument doc = new XmlDocument();
                  doc.LoadXml(geo);
                  {
                     XmlNode r = doc.SelectSingleNode("/reversegeocode/result");
                     if(r != null)
                     {
                        ret = new Placemark(r.InnerText);

                        XmlNode ad = doc.SelectSingleNode("/reversegeocode/addressparts");
                        if(ad != null)
                        {
                           var vl = ad.SelectSingleNode("country");
                           if(vl != null)
                           {
                              ret.CountryName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("country_code");
                           if(vl != null)
                           {
                              ret.CountryNameCode = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("postcode");
                           if(vl != null)
                           {
                              ret.PostalCodeNumber = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("state");
                           if(vl != null)
                           {
                              ret.AdministrativeAreaName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("region");
                           if(vl != null)
                           {
                              ret.SubAdministrativeAreaName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("suburb");
                           if(vl != null)
                           {
                              ret.LocalityName = vl.InnerText;
                           }

                           vl = ad.SelectSingleNode("road");
                           if(vl != null)
                           {
                              ret.ThoroughfareName = vl.InnerText;
                           }
                        }

                        status = GeoCoderStatusCode.G_GEO_SUCCESS;
                     }
                  }
               }
            }
             }
             catch(Exception ex)
             {
            ret = null;
            status = GeoCoderStatusCode.ExceptionInCode;
            Debug.WriteLine("GetPlacemarkFromReverseGeocoderUrl: " + ex);
             }

             return ret;
        }
Пример #48
0
 public GeoCoderStatusCode GetPoints(Placemark placemark, out List<PointLatLng> pointList)
 {
     return GetLatLngFromGeocoderUrl(MakeGeocoderDetailedUrl(placemark), out pointList);
 }