现在我正在尝试获取我的当前位置,但我无法仅获取一个位置37.4219983,-122.084这是我无法获取我的真实位置的任何位置,这是我的代码
private void getDeviceLocation(){
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
try{
if(mLocationPermissionsGranted){
final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()){
Location currentLocation = (Location) task.getResult();
current_lat=currentLocation.getLatitude();
current_lng=currentLocation.getLongitude();
Log.e("currentLocation",current_lat+"....."+current_lng);
moveCamera(new LatLng(current_lat,current_lng),
15f);
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
mMap.clear();
MarkerOptions markerOptions=new MarkerOptions();
markerOptions.position(new LatLng(latLng.latitude,latLng.longitude)).title("disance");
float[]results=new float[10];
Location.distanceBetween(current_lat,current_lng,latLng.latitude,latLng.longitude,results);
markerOptions.snippet("ditance ="+results[0]);
mMap.addMarker(markerOptions);
}
});
mMap.clear();
}else{
Toast.makeText(add_center_map.this, "unable to get current location", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
}
}
private void moveCamera(LatLng latLng, float zoom){
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
}
答案 0 :(得分:0)
您可能正在模拟器中对此进行测试。它的位置设置为
经度:-122.0840纬度:37.4220海拔:0.0
默认情况下。
您可以在真实设备上进行测试,也可以在其扩展控件(AVD旁边的三个点)中为虚拟设备配置其他坐标。