Android
구글지도 위도, 경도값 받아오지못하는 에러
void
2017. 6. 30. 16:58
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation();
LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
이런식으로 위도, 경도 받아오려했다.
Attempt invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference
하지만 위도, 경도를 받아오지못했고
참고 스택오버플로우를 보고
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
String locationProvider = LocationManager.NETWORK_PROVIDER;
location = locationManager.getLastKnownLocation(locationProvider);
변경하니 에러해결