[英]How to use geo-location in a xamarin forms web view page
I am writing a app that needs to open the mobile forcast.io website I am using xamarin forms to do this. 我正在编写一个需要打开移动forcast.io网站的应用程序,而我正在使用xamarin表单来执行此操作。 it loads the mobile website just fine but it does not pull up the current location!
它可以很好地加载移动网站,但不会拉出当前位置! now if I go to the site in chrome browser for android it works just fine here is my code:
现在,如果我进入chrome浏览器中的android站点,则可以正常工作,这是我的代码:
using Xamarin.Forms;
namespace App.Radar
{
public partial class RadarHome : ContentPage
{
public RadarHome()
{
var browser = new WebView();
{
browser.Source = "https://forecast.io";
Content = browser;
};
}
}
}
and here is what my output log says: 这是我的输出日志说的:
[INFO:CONSOLE(0)] "Use of the Application Cache is deprecated on insecure origins. Support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See google url for more details.", source: (0)
08-09 09:12:25.332 I/chromium( 5979): [INFO:CONSOLE(0)] "Use of the Application Cache is deprecated on insecure origins. Support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See google url for more details.", source: (0)
[INFO:CONSOLE(1)] "getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See google url for more details.", source: http://forecast.io/js/mobile.min.js?rel=1454000774782 (1)
08-09 09:12:33.522 I/chromium( 5979): [INFO:CONSOLE(1)] "getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See google url for more details.", source: http://forecast.io/js/mobile.min.js?rel=1454000774782 (1)
08-09 09:12:34.002 W/cr_BindingManager( 5979): Cannot call determinedVisibility() - never saw a connection for the pid: 5979
08-09 09:12:46.452 D/Mono ( 5979): [0xd89ff930] worker finishing
Thread finished: <Thread Pool> #4
08-09 09:12:48.452 D/ViewRootImpl( 5979): ViewPostImeInputStage processPointer 0
08-09 09:12:48.532 D/ViewRootImpl( 5979): ViewPostImeInputStage processPointer 1
I'm testing this on a Samsung galaxy s7 running api 23. 我正在运行api 23的三星s7上对此进行测试。
Why isn't it getting my current location? 为什么没有得到我的当前位置?
Hello I'm proving your app, and I don't have this problem with the GPS. 您好,我正在验证您的应用,而GPS则没有此问题。
You are working in a with a real phone, when you debug in your 当您在自己的手机中进行调试时,您正在使用真实的电话
Deployed AndroidManifest.xml need to add android permissions to the application can use the gps. 部署AndroidManifest.xml时需要向应用程序添加android权限才能使用gps。
https://developer.xamarin.com/recipes/android/general/projects/add_permissions_to_android_manifest/ https://developer.xamarin.com/recipes/android/general/projects/add_permissions_to_android_manifest/
rigth click in the android project -> android manifest and activate in the list the permissions necessary to work with the gps 右键单击android项目-> android清单,然后在列表中激活使用gps所需的权限
INTERNET – for accessing network resources. INTERNET –用于访问网络资源。
ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION – for location services. ACCESS_COARSE_LOCATION和ACCESS_FINE_LOCATION –用于定位服务。
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////// /////////////////
search the option of location and wath is enable 搜索位置选项,并启用wath
I probe the app in my table and the location that the application take is the location relative of the my public ip. 我在表中探测了该应用程序,该应用程序所采用的位置是我的公共IP的相对位置。 And I thinking because this a external web page, the took the location of my provider of internet .
我在想,因为这是一个外部网页,所以成为了我的互联网提供商的位置。
////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////// ////////////////////
I have an idea try this 我有个主意试试看
http://www.c-sharpcorner.com/UploadFile/8c19e8/xamarin-android-working-with-gps-and-locations/ http://www.c-sharpcorner.com/UploadFile/8c19e8/xamarin-android-working-with-gps-and-locations/
create a method that save the Latitude and Longitude of the phone. 创建一种保存手机纬度和经度的方法。
public double Latitude { get; set; }
public double Longitude { get; set; }
and when you save this parameters y the Api of forecast 当您保存此参数y的预测Api
https://developer.forecast.io/docs/v2 https://developer.forecast.io/docs/v2
There are two types of API calls. 有两种类型的API调用。 A forecast request returns the current forecast (for the next week):
预测请求将返回当前预测(针对下一周):
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE A time-machine request returns the observed weather at a given time (for many places, up to 60 years in the past): https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE时间机器请求会返回给定时间(对于很多地方,过去60多年)的观测天气:
https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME https://api.forecast.io/forecast/APIKEY/纬度,经度,时间
**replaces the default link for this with the parameter and you have the current weather ** **为此参数替换默认链接,您便拥有当前天气**
Regards. 问候。 I hope you have a nice day.
我希望你有个美好的一天。 Happy coding.
快乐的编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.