如何在xamrian表单Web视图页面中使用地理位置

时间:2016-08-09 16:46:08

标签: c# android xamarin xamarin.forms

你好我正在编写一个需要打开手机forcast.io网站的应用程序我正在使用xamrian表单来执行此操作。它加载移动网站就好了,但它没有拉起当前的位置!现在,如果我在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;

            };



        }
    }
}

这是我的输出日志所说的:

[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
我在运行api 23的三星galaxy s7上测试了这个。

关于为何没有获取我当前位置的任何想法?

提前致谢! :)

1 个答案:

答案 0 :(得分:0)

您好我已经证明了您的应用,并且我没有使用GPS这个问题。

example

当您在

中进行调试时,您正在使用真实手机

部署的AndroidManifest.xml需要向应用程序添加android权限才能使用gps。

https://developer.xamarin.com/recipes/android/general/projects/add_permissions_to_android_manifest/

在android项目中点击一下 - &gt; android清单并在列表中激活 使用gps所需的权限

Android Manifest

INTERNET - 用于访问网络资源。

ACCESS_COARSE_LOCATION和ACCESS_FINE_LOCATION - 用于位置服务。

/////////////////////////////////////////////// ////////////////////

搜索位置选项并启用wath

menu

location

我在我的表中探测应用程序,应用程序占用的位置是我公共ip的相对位置。我想,因为这是一个外部网页,它占据了我的互联网提供商的位置。

/////////////////////////////////////////////// ///////////////////////

我有个想法试试这个

http://www.c-sharpcorner.com/UploadFile/8c19e8/xamarin-android-working-with-gps-and-locations/

创建一种保存手机纬度和经度的方法。

    public double Latitude { get; set; }  
    public double Longitude { get; set; }  

当您将此参数保存为预测的Api时

https://developer.forecast.io/docs/v2

有两种类型的API调用。预测请求会返回当前预测(下周):

https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE 时间机器请求返回在给定时间观察到的天气(对于许多地方,过去最多60年):

https://api.forecast.io/forecast/APIKEY/LATITUDE,LONGITUDE,TIME

**使用参数替换此默认链接,并且您拥有当前天气**

的问候。我希望你有个美好的一天。快乐的编码。