谷歌地图API的Andr​​oid V2 - " ACCESS_FINE_LOCATION"我的定位层所需权限启用 [英] Google Maps API Android v2 - "ACCESS_FINE_LOCATION" permission required with my-location layer enabled

查看:201
本文介绍了谷歌地图API的Andr​​oid V2 - " ACCESS_FINE_LOCATION"我的定位层所需权限启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示的用户在谷歌地图上的位置,使<一href="http://developer.android.com/reference/com/google/android/gms/maps/GoogleMap.html#setMyLocationEnabled%28boolean%29"相对=nofollow>我的定位层,但此功能需要的 ACCESS_FINE_LOCATION 权限来从GPS的位置。 是否有可能以prevent的 GoogleMap的从试图从GPS得到的位置?

如果我删除权限 ACCESS_FINE_LOCATION 在清单文件,当我试图以显示地图,应用程序崩溃,出现以下错误:

  E / AndroidRuntime(28578):致命异常:主要
E / AndroidRuntime(28578):java.lang.SecurityException异常:客户必须有ACCESS_FINE_LOCATION权限申请PRIORITY_HIGH_ACCURACY位置。
E / AndroidRuntime(28578):在android.os.Parcel.readException(Parcel.java:1425)
E / AndroidRuntime(28578):在android.os.Parcel.readException(Parcel.java:1379)
E / AndroidRuntime(28578):在bbj.a(的SourceFile:424)
E / AndroidRuntime(28578):在bbn.a(的SourceFile:232)
E / AndroidRuntime(28578):在maps.al.bj(来源不明)
E / AndroidRuntime(28578):在uh.h(的SourceFile:642)
E / AndroidRuntime(28578):在un.a(的SourceFile:399)
E / AndroidRuntime(28578):在uj.a(的SourceFile:158)
E / AndroidRuntime(28578):在ui.handleMessage(的SourceFile:111)
E / AndroidRuntime(28578):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(28578):在android.os.Looper.loop(Looper.java:137)
E / AndroidRuntime(28578):在android.app.ActivityThread.main(ActivityThread.java:5041)
E / AndroidRuntime(28578):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(28578):在java.lang.reflect.Method.invoke(Method.java:511)
E / AndroidRuntime(28578):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
E / AndroidRuntime(28578):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E / AndroidRuntime(28578):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

您可以使用 LocationSource 模式来提供自己的位置,这可能来自别的什么东西。 LocationSource 是一个接口,您将实施的一些对象,可以提供位置数据。您注册此与 setLocationSource() GoogleMap的。您可以实现启动()关闭()你的方法 LocationSource 将被调用,让你知道什么时候应该开始和停止推动了地方。当你的位置修正,你叫 onLocationChanged()上所提供的 OnLocationChangedListener

演示使用的示例项目 LocationSource

I want to show the location of the user on a Google Maps enabling my-location layer, but this functionality requires the "ACCESS_FINE_LOCATION" permission to get the location from the GPS. Is it possible to prevent the GoogleMap from trying to get the location from the GPS?

If I remove the permission "ACCESS_FINE_LOCATION" in the Manifest file, as soon as I try to display the map, the app crashes with the following error:

E/AndroidRuntime(28578): FATAL EXCEPTION: main
E/AndroidRuntime(28578): java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
E/AndroidRuntime(28578):    at android.os.Parcel.readException(Parcel.java:1425)
E/AndroidRuntime(28578):    at android.os.Parcel.readException(Parcel.java:1379)
E/AndroidRuntime(28578):    at bbj.a(SourceFile:424)
E/AndroidRuntime(28578):    at bbn.a(SourceFile:232)
E/AndroidRuntime(28578):    at maps.al.b.j(Unknown Source)
E/AndroidRuntime(28578):    at uh.h(SourceFile:642)
E/AndroidRuntime(28578):    at un.a(SourceFile:399)
E/AndroidRuntime(28578):    at uj.a(SourceFile:158)
E/AndroidRuntime(28578):    at ui.handleMessage(SourceFile:111)
E/AndroidRuntime(28578):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(28578):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(28578):    at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime(28578):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28578):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(28578):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime(28578):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime(28578):    at dalvik.system.NativeStart.main(Native Method)

解决方案

You can use the LocationSource pattern to supply your own locations, which could come from whatever. LocationSource is an interface, which you would implement on some object that can supply location data. You register this with setLocationSource() on the GoogleMap. You implement activate() and deactivate() methods on your LocationSource that will get called to let you know when you should start and stop pushing over locations. As you get location fixes in, you call onLocationChanged() on a supplied OnLocationChangedListener.

This sample project demonstrates the use of LocationSource.

这篇关于谷歌地图API的Andr​​oid V2 - &QUOT; ACCESS_FINE_LOCATION&QUOT;我的定位层所需权限启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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