Hi,
Does any one have an example how to use geolocation?
Thanks
Hi again António,
Please note that some browsers (if not all) only support location requests on an HTTPS web page
Starting with Chrome 50, Chrome no longer supports obtaining the user’s location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that’s making the Geolocation API call must be served from a secure context such as HTTPS.
Hi António,
I presume that by “run on the server” you mean open the web page on a browser running on the server.
Geolocation API is an HTML5 feature used by JavaScript code that runs on the browser, provided the browser is allowed to access the location. I presume the problem you are facing is the lack of browser’s permission.
Please go to https://www.w3schools.com/html/html5_geolocation.asp and click the blue button Try it. The browser should ask your permission to access the location.
It’s working now! Thanks!
But when I run on my pc it returns the coordenates but on the server IIS always return zero. I’ve tried on two servers. What could cause that?
Hi António,
Please note that awaitable methods were introduced in Wisej 1.5.12 as you can see on Wisej Release Notes 1.5.12
WJ-9099 – Enhancement – Wisej.Ext.Geolocation: Added awaitable method.
Thanks for your answer but i get this error
private async void buttonCurrentLocation_Click(object sender, EventArgs e)
{
var position = await geolocation.GetCurrentPositionAsync(); <—- Error
this.maskedTextBoxLat.Text = position.Latitude.ToString();
this.maskedTextBoxLng.Text = position.Longitude.ToString();
}
Error 47 ‘Wisej.Web.Ext.GoogleMaps.GoogleMap’ does not contain a definition for ‘GetGeocodeAsync’ and no extension method ‘GetGeocodeAsync’ accepting a first argument of type ‘Wisej.Web.Ext.GoogleMaps.GoogleMap’ could be found (are you missing a using directive or an assembly reference?)
Hi António,
Pleae have a look at our Wisej-Examples GitHub repository. The GoogleMaps example includes an example of GeoLocation, namely on MapPage.cs, the CurrentLocation button click handler
Snippet
var position = await geolocation.GetCurrentPositionAsync(); this.maskedTextBoxLat.Text = position.Latitude.ToString(); this.maskedTextBoxLng.Text = position.Longitude.ToString();
HTH
Please login first to submit.