我需要从mapquestapi获取第一个和最后一个纬度和经度,并通过街道地址。首先,传递lat和long我可以使用json.net获取house_number:
string latitu = "-33.4479021";
string longitu = "-70.6447504";
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&lat=" + latitu + "&lon=" + longitu + "");
StreamReader reader = new StreamReader(stream);
Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());
string houseNumber = (string)jObject["address"]["house_number"];
Console.WriteLine(houseNumber);
stream.Close();
下面的代码工作正常,但现在我需要从“svg”获取第一个和最后一个lat和long:
array (
0 => array
( 'place_id' => '92911594',
'licence' =>
'Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright',
'osm_type' => 'way',
'osm_id' => '121748552',
'boundingbox' => array
(
0 => '-33.4480414',
1 => '-33.4439319',
2 => '-70.6448054',
3 => '-70.6266944',
),
'lat' => '-33.4460658',
'lon' => '-70.6359402',
'display_name' => 'MarÃn, Santiago, Provincia de Santiago, XIII Región Metropolitana de Santiago, 8331059, Chile',
'class' => 'highway',
'type' => 'tertiary',
'importance' => 0.2,
'address' => array
(
'road' =>
'MarÃn',
'city' =>
'Santiago',
'county' =>
'Provincia de Santiago',
'state' => 'XIII Región Metropolitana de Santiago',
'postcode' => '8331059',
'country' => 'Chile',
'country_code' => 'cl',
),
**'svg'** => 'M **-70.626694400000005 33.444016900000001** L -70.626853100000005 33.443931900000003 -70.628024600000003 33.444266200000001 -70.629083399999999 33.444542800000001 -70.629957200000007 33.444764300000003 -70.630791099999996 33.444983999999998 -70.630836099999996 33.4449915 -70.631027500000002 33.445031299999997 -70.631102900000002 33.445044099999997 -70.631955300000001 33.445186900000003 -70.632777300000001 33.445343999999999 -70.632846900000004 33.445356799999999 -70.6329025 33.445371799999997 -70.633783199999996 33.445576199999998 -70.634021200000007 33.445624299999999 -70.635066499999994 33.4458354 -70.635940199999993 33.4460658 -70.637316900000002 33.446388900000002 -70.638039300000003 33.446610700000001 -70.638551500000005 33.446730799999997 -70.639778699999994 33.447019400000002 -70.640489099999996 33.4471962 -70.641005800000002 33.4473074 -70.642197100000004 33.447521299999998 -70.642251900000005 33.447535500000001 -70.643692900000005 33.4478121 **-70.644805399999996 33.448041400000001**',
), )
我正在尝试这个,但错误说它不是一个对象:
string direcc = "marin,+santiago";
//string url = "http://open.mapquestapi.com/nominatim/v1/search?&q="+direcc+"&format=json&addressdetails=1&limit=1&polygon_svg=1&countrycodes=cl";
WebClient client = new WebClient();
Stream stream = client.OpenRead("http://open.mapquestapi.com/nominatim/v1/search?&q=" + direcc + "&format=json&addressdetails=1&limit=1&polygon_svg=1&countrycodes=cl");
StreamReader reader = new StreamReader(stream);
Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());
string la = (string)jObject["address"]["svg"];
Console.WriteLine(la);
stream.Close();
这项工作,但我不知道如何获得第一个和最后一个lat和long:
string latitud = "-33.4479021";
string longitud = "-70.6447504";
string url = "http://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&lat=" + latitud +"&lon=" + longitud + "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string xmlText = reader.ReadToEnd();
Console.WriteLine(xmlText);
我能做些什么才能得到这个部分? 非常感谢你!