开发者

Webcontrol in Webservice

I need a Webcontrol (System.Windows.Forms.W开发者_高级运维ebBrowser) in my Webservice, because I have to calculate distances between coordinates and for that I'll use Google Maps (geocoder). With the Webcontrol I could execute my javascript code to calculate the distance (WebControl.Document.InvokeScript).

Is there any way to get a webcontrol in a webservice? Or is there another, easier way to accomplish my task?


The Geocoding API doesn't only work through JavaScript. Instead of JavaScript you can also request a json or an xml response using the URL get request. (see https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses) For example:

http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

Here is how I did it:

System.Xml.XmlDocument document = new XmlDocument();
//Request XML through Google API
document.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false");

//Parse output
XmlNodeList latNodeList = document.GetElementsByTagName("lat");
XmlNodeList lngNodeList = document.GetElementsByTagName("lng");
String lat = latNodeList.Item(0).InnerText;
String lng = lngNodeList.Item(0).InnerText;

However, based on what you want (calculate distance) I think Google Distance Matrix API is something you are looking for. (https://developers.google.com/maps/documentation/distancematrix/)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜