You are here:

VB.NET/GeckoFX Geolocation

Advertisement


Question
I am a Novice VB.NET programmer and have created a HTML file which when navigated to, will display the users co-ordinates using W3C.
Now, I need to integrate this into my Windows Forms application.
I have heard that W3C Geolocation is Internet Explorer (v9.0+) or Firefox (3.5+) or Chrome (5.0+) or Safari (5.0+) or Opera (10.60+)
I have tried using the WebBrowser control, but that is not compatible, GeckoFX 1.9.1 is incompatible somehow, and I haven't tried anything else. From here, I would like to somehow take the output from the little API I made, read it and put it into two seperate strings, if you could help me there too.

It is against the terms and conditions to include download links, so I will put the HTML here and I am sure you are capable of compiling/viewing it in a web browser yourself:

<html><head>
<title>Extremely basic example of the W3C Geolocation API</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<script type="text/javascript">
//Check if browser supports W3C Geolocation API
if (navigator.geolocation) {
 navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
 } else {
 alert('Geolocation is required for this page, but your browser doesn't support it.');
}

function successFunction(position) {
 var lat = position.coords.latitude;
 var lon = position.coords.longitude;
 document.getElementById('latvar').innerHTML = lat;
 document.getElementById('lonvar').innerHTML = lon;
}

function errorFunction(position) {
 alert('Error!');
}
</script>
<b id = 'latvar'></b><p>
<b id = 'lonvar'></b>
</head><body>
</p></body></html>

Answer
You can use the WebBrowser control to get reference to the DOM's Document object and then use the DOM API to extract values from elements called latvar and lonvar.

this should provide a starting point: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.document

Regards,
Riz

VB.NET

All Answers


Answers by Expert:


Ask Experts

Volunteer


Syed Rizwan Muhammad Rizvi

Expertise

I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.

Experience

Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.

©2016 About.com. All rights reserved.