简体   繁体   中英

How to use webBrowser control in c# to get user google latitude and longitude?

我可以使用c#webrowser控件来获取谷歌javascript api v3的纬度和经度吗?

You don't have to use any javascript API from Google to get geocode data. Simply use the WebRequest object and read the result from the XML file provided by the geocode service.

WebRequest req = System.Net.WebRequest.Create("your adress");
WebResponse response = req.GetResponse();

From there, you can get the Stream and create a StreamReader as follow:

Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);

After that, simply decode the XML by using the element tag "lat" and "lng". You should then be able to get the data you are looking for.

For more information, and particulary the terms of service for using the Google Geocode Service, visit the Google Maps API website.

            string strSelect = textBoxGpsLatitude.Text;
            strSelect += ",";
            strSelect += textBoxGpsLongitude.Text;

            webBrowser3.Navigate("http://maps.google.com/maps?q=" + strSelect, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM