Xamarin Android WebView geolocation wrong on mobile
 
English Exp.
The yandex map in Android WebView did not show the current location exactly.
The same page was showing correctly when opened from the browser.
It has improved after various settings have been made to WebView. The changes are as follows.

Türkçe Açk.
Android WebView içerisinde yandex harita konumu tam doğru göstermiyordu. 
Aynı sayfa tarayıcıdan açıldığında doğru gösteriyordu. 
WebView'e çeşitli ayarlar yapıldıktan sonra düzeldi. Değişiklikler aşağıdaki gibidir.


OLD CODE
myWebView.SetWebChromeClient(new WebChromeClient());
myWebView.SettingsJavaScriptEnabled = true;

NEW CODE

myWebView.SetWebViewClient(new GeoWebViewClient());
myWebView.SetWebChromeClient(new GeoWebChromeClient());

myWebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
myWebView.Settings.DomStorageEnabled = true;
myWebView.Settings.JavaScriptEnabled = true;
myWebView.Settings.SetGeolocationEnabled(true);

NEW CODE - NEW CLASSES
 
public class GeoWebChromeClient : WebChromeClient
{
	public override void OnGeolocationPermissionsShowPrompt(string origin, GeolocationPermissions.ICallback callback)
	{
		callback.Invoke(origin, true, false);
	}
}

public class GeoWebViewClient : WebViewClient
{
	public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
	{
		Android.Net.Uri url = request.Url;
		view.LoadUrl(url.ToString());
		return true;
	}
	public override void OnReceivedSslError(WebView view, SslErrorHandler handler, Android.Net.Http.SslError er)
	{
		// Ignore SSL certificate errors
		handler.Proceed();
	}
}	

TAGS
{

android webview ymaps.geolocation.get
yandex map api android geolocation wrong
yandex android geolocation mobile wrong
xamarin OnGeolocationPermissionsShowPrompt
Location is accessed in Chrome, doesn't work in WebView
SetGeolocationEnabled wrong
webchromeClient location access
}
 

Author: Engin ATALAY
Date: 27.03.2020 09:45:43
View Count: 304
 
 

COMMENTS
 
No comments yet. Be the first to comment who you are.
 
 
 
 
 
 
 
WRITE COMMENT
 
 
Your Name :
 
 
 
E-mail :
 
 
 
Your Message :
 
 
 
 
 
 
 
This project : ASP.NET MVC , RAZOR, Entity Framework , CSS , HTML , JQUERY(2.0.2) , AJAX the C# side-tier architecture was developed with logic.
 
Yukarı Çık