IOS7中当前位置经纬度的不同行为 [英] different behaviour for current location latitude and longitude in iOS7 to IOS8

查看:482
本文介绍了IOS7中当前位置经纬度的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将xamarin用于当前位置 currentLocation示例
我使用上面的链接获取当前位置的经纬度。

在升级到IOS 8之前的IOS 7中它显示了我的当前位置在模拟器和设备上的经纬度(它看起来很奇怪对于我在模拟器获取当前位置的经度和纬度)。

升级到iOS 8并运行相同的代码后,它给了



在模拟器中:(打开wifi无SIM卡位置服务应用程序始终。)

 结果:
纬度= 37.785834。
经度= -122.406517。

开启设备IPhone5c(打开wifi无SIM卡位置服务应用程序始终。)

 结果:
纬度= 37.785834。
经度= -122.406517。

(但我预计我目前的位置经纬度)

升级后,它不会询问,该应用程序就像使用您当前的位置GPS。一个警告信息,包含YES,NO选项。



如何获取我当前位置的经纬度? 解决方案

您需要从iOS 8.0开始明确请求权限。步骤如下:


  1. 更新您的Info.plist文件。插入新密钥:NSLocationAlwaysUsageDescription 或 NSLocationWhenInUseUsageDescription 键并写入当您的应用请求权限时显示的自定义消息。

  2. ol>

    在plist文件中必须有这些键中的任意一个,否则权限请求将不会显示!如果您不想在警报视图中显示自定义说明文本,请将该键的值字符串留空,但您仍然必须在Info.plist文件中出现密钥!



    在您开始跟踪之前,请检查您是否在iOS8上,然后从CLLocationManager实例发送RequestAlwaysAuthorization或RequestWhenInUseAuthorization。示例:

      var locationManager = new CLLocationManager(); 
    if(UIDevice.CurrentDevice.CheckSystemVersion(8,0)){
    locationManager.RequestAlwaysAuthorization();





    $ p
    $ b $ p
    $ b

    在这种情况下,使用Info.plist文件中的NSLocationAlwaysUsageDescription项。请注意,Xamarin Studio目前不会从下拉列表中自动为您提供此密钥,您必须在此处手动输入/复制粘贴此密钥。


    Using xamarin for current location currentLocation example I used the above Link for getting current location latitude and longitude.
    In IOS 7 before upgrade to IOS 8 Its shows my current location latitude and longitude on both simulator and device.(Its looks strange for me in simulator for getting current location latitude and longitude).

    After upgrade to iOS 8 and run same code it give

    In simulator:(Turn on wifi no sim card location service App always.)

    Result:
    latitude = 37.785834.
    longitude = -122.406517.
    

    On Device IPhone5c (Turn on wifi no sim card location service App always.)

    Result:
    latitude = 37.785834.
    longitude = -122.406517.
    

    (But I expected my current location latitude and longitude )

    After upgrade it does not ask, that application like use the Your Current Location GPS. an Alert message with YES, NO options.

    How to get my current location latitude and longitude?

    解决方案

    You need to request permission explicitly from iOS 8.0 onwards. The steps to do so:

    1. Update your Info.plist file. Insert a new key: either NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys and write the custom message that will be displayed when your app requests the permission.

    It is a must to have either of these keys in your plist file otherwise the permission request won't be displayed! If you don't want to show a custom explanation text in the alertview, leave the key's value string empty, but you still must have the key present in the Info.plist file!

    1. Before you start tracking, check that you are on iOS8 then send either RequestAlwaysAuthorization or RequestWhenInUseAuthorization from the CLLocationManager instance. Example:

      var locationManager = new CLLocationManager();
      if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
          locationManager.RequestAlwaysAuthorization();
      }
      

    In this case, use the NSLocationAlwaysUsageDescription key in your Info.plist file. Please note, Xamarin Studio does not currently offer you this key automatically from the dropdown list, you have to enter / copy-paste this key manually there.

    这篇关于IOS7中当前位置经纬度的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆