Getting Latitude and Longitude 0.0 in Android M

前端 未结 4 1460
陌清茗
陌清茗 2020-12-15 01:26

I am suffering from the problem of getting value 0.0 as latitude and longitude in Android Marshmallow (API 23) i.e. 6.0.

I have searched a lot regar

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 02:10

    First, remove these:

    
    
    

    Those are defined by the platform, not you.

    Also, you are not reacting when the user actually grants permission to you. Request the permissions in your activity, and do not create an instance of GPSTracker until you have permission. That may be immediately, if checkSelfPermission() says that you have permission. Otherwise, that will be when the activity is called with onRequestPermissionResult().

    The location work itself is also buggy, in that you seem to think that you will get a location immediately, which will not be the case much of the time.

提交回复
热议问题