From: <lk...@us...> - 2008-01-16 13:45:29
|
Revision: 1252 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1252&view=rev Author: lkuech Date: 2008-01-16 05:45:22 -0800 (Wed, 16 Jan 2008) Log Message: ----------- Worldmap: Prepared to switch the AdressSearch from Yahoo! to Google, because it covers much more Aerias of the World. Modified Paths: -------------- trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs trunk/plugins/WorldMap/WorldmapSearch.cs Modified: trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs =================================================================== --- trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2008-01-16 06:20:58 UTC (rev 1251) +++ trunk/plugins/WorldMap/MAPS/SearchGeoCodes.cs 2008-01-16 13:45:22 UTC (rev 1252) @@ -13,6 +13,7 @@ { OpenGeoCoding, YahooGeoCoding, + GoogleGeoCoding, GeoNames } @@ -38,6 +39,12 @@ public void SearchNow() { + if (ServiceName == GeoCodeService.GoogleGeoCoding) + { + Uri url = GetGoogleAdress(); + string XMLString = GetXMLResult(url); + PushGoogleResultToSearchResult(XMLString); + } if (ServiceName == GeoCodeService.YahooGeoCoding) { Uri url = GetYahooAdress(); @@ -157,6 +164,50 @@ } } + public void PushGoogleResultToSearchResult(string XMLString) + { + SearchResult = new List<GeoCode>(); + SearchResult.Clear(); + + if (XMLString == null) return; + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(XMLString); + + XmlNode root = doc.DocumentElement; + root = root["Response"]; + + XmlNodeList nodes = root.ChildNodes; + + + System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture; + System.Globalization.NumberFormatInfo ni = (System.Globalization.NumberFormatInfo)ci.NumberFormat.Clone(); + ni.NumberDecimalSeparator = "."; + ni.NumberGroupSeparator = ","; + + foreach (XmlNode node in nodes) + { + if(node.Name == "Status") + { + Debug.WriteLine(String.Format("WorldMap Google GeoCodeSearch. Request:{0} ReturnCode: {1}", node["request"].InnerText, node["code"].InnerText)); + } + + if (node.Name == "Placemark") + { + GeoCode tmpGeoCode = new GeoCode(); + tmpGeoCode.Name = node["address"].InnerText; + + XmlNode PointNode = node["Point"]; + string Coordinates = PointNode.FirstChild.InnerText; + string longitude = Coordinates.Split(new char[] { ',' })[0]; + string latitude = Coordinates.Split(new char[] { ',' })[1]; + tmpGeoCode.Longitude = double.Parse(longitude, ni); + tmpGeoCode.Latitude = double.Parse(latitude, ni); + SearchResult.Add(tmpGeoCode); + } + } + } + public Uri GetYahooAdress() { string url = "http://local.yahooapis.com/MapsService/V1/geocode?appid=MediaPortalWorldmap&output=xml"; @@ -182,6 +233,36 @@ } + public Uri GetGoogleAdress() + { + // right now the key is found somewhere at the internet. Why have to get our own... + string url = "http://maps.google.com/maps/geo?output=xml&key=ABQIAAAA5rWB_5p0XK5Y2Qzsyd6HpxSPVks7h_CYIzXuM6UMzYp2f8KU7RQbRo0p7vACcXJ1w39qEH6JPQL_xg&q="; + + int valuesAdded = 0; + + if (Street != "") + { + url += Street; + valuesAdded++; + } + if (City != "") + { + if (valuesAdded > 0) url += ","; + url += City; + valuesAdded++; + } + if (Country != "") + { + if (valuesAdded > 0) url += ","; + url += Country; + valuesAdded++; + } + url = ConvertStringToSafeUrl(url); + + return new Uri(url); + } + + /// <summary> /// Converts special characters to safe ones (e.g. \xFC becomes %FC) /// </summary> Modified: trunk/plugins/WorldMap/WorldmapSearch.cs =================================================================== --- trunk/plugins/WorldMap/WorldmapSearch.cs 2008-01-16 06:20:58 UTC (rev 1251) +++ trunk/plugins/WorldMap/WorldmapSearch.cs 2008-01-16 13:45:22 UTC (rev 1252) @@ -236,7 +236,11 @@ if (searchType == SearchType.Place) tmpWin.SuggestedZoomLevel = 13; else { - if (lblStreet.Label != "") tmpWin.SuggestedZoomLevel = 16; + if (lblStreet.Label != "") + { + tmpWin.SuggestedZoomLevel = 16; + if (tmpMainWindow.currentMapType == MAPS.MapFunctions.MapType.GMTerrain) tmpWin.SuggestedZoomLevel = 15; + } if (lblStreet.Label == "" && lblCity.Label != "") tmpWin.SuggestedZoomLevel = 11; if (lblStreet.Label == "" && lblCity.Label == "" && lblCountry.Label != "") tmpWin.SuggestedZoomLevel = 5; } @@ -276,7 +280,7 @@ Street = lblStreet.Label; City = lblCity.Label; Country = lblCountry.Label; - tmpSearch.ServiceName = MAPS.GeoCodeService.YahooGeoCoding; + tmpSearch.ServiceName = MAPS.GeoCodeService.GoogleGeoCoding; } if (searchType == SearchType.Place) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |