0
我想獲得當前位置和移動相機的當前位置,然後保存當前位置(經緯度)到我的數據庫獲取當前位置經緯度和LNG在地圖上的準備
我得到ACCESS_FINE許可 和使用下面的代碼,但應用程序已停止工作
double lat = map.getMyLocation().getLatitude();
double lng = map.getMyLocation().getLongitude();
LatLng cur = new LatLng(lat,lng);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(cur, 17));
的Android日誌貓:
java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference
你是否檢查過map.getMyLocation的值?他們可能是空:),請張貼你得到的錯誤,否則我們無法真正幫助你。 –
stacktrace請 –
請檢查安全權限和緯度是否爲空 – Saveen