我知道這個問題之前已被問過,但我沒有得到解決方案。我的android應用程序開始顯示我在非洲的位置,然後相機移動到我目前的位置。任何人都可以幫助理解這種行爲,並提供一些解決方案來解決這個問題。谷歌地圖開始顯示我的當前位置從非洲,然後移動相機到我目前的位置
下面是我的代碼部分
//ON CONNECTION SUCCESSFUL USING GOOGLECLIENTAPI
@Override
public void onConnected(Bundle bundle) {
checkPermission();
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
if (location != null) {
pointUserCurrentLocationOnMap(location);
userLocation = location;
saveLocationIfDoesNotExistInSqliteAndBackend();
} else {
checkSettingIsProper();
}
}
public void pointUserCurrentLocationOnMap(Location lastknownLocation) {
mMap.clear();
enableUserLocationButton(true);
userLocation = lastknownLocation;
currentLocation = new LatLng(lastknownLocation.getLatitude(), lastknownLocation.getLongitude());
MarkerOptions markerOptions = new MarkerOptions().position(currentLocation).title("You");
Marker marker = mMap.addMarker(markerOptions);
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_person_pin_circle_black_24dp));
marker.showInfoWindow();
//bounds= latlngbound which is initialize when user search some thing
if (bounds != null) {
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, (int) JobSmithApplication.convertPixelsToDp(50f, this)));
} else {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLocation, 14f));
}
mMap.setOnMarkerClickListener(this);
mMap.setOnMyLocationButtonClickListener(this);
}
是什麼錯我的代碼?
你可以提供一些文檔鏈接,這樣我就可以在更深入地閱讀它 – FaisalAhmed
試試這個.... HTTPS://www.androidtutorialpoint.com/intermediate/android-map-app-showing-current-location-android/ –
您提供的鏈接不會說有關默認座標0.0的任何內容,這是在非洲。不過,我找到了解決方案。我正在使用導致問題的animateCamera()。解決方案是使用moveCamera(),因爲他說[這裏](http://stackoverflow.com/questions/21530315/is-it-possible-in-android-google-maps-to-change-default-location-from- south-afri/21530461#21530461) – FaisalAhmed