How to get the current location in Google Maps Android API v2?

前端 未结 13 1145
Happy的楠姐
Happy的楠姐 2020-11-27 12:32

Using

mMap.setMyLocationEnabled(true)

can set the myLocation layer enable.
But the problem is how to get the myLocation when the user

13条回答
  •  眼角桃花
    2020-11-27 13:20

    try this

    LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    String provider = service.getBestProvider(criteria, false);
    Location location = service.getLastKnownLocation(provider);
    LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
    

提交回复
热议问题