【问题标题】:why its not my current location only one location 37.4219983,-122.084?为什么不是我当前的位置只有一个位置 37.4219983,-122.084?
【发布时间】:2019-09-18 10:50:57
【问题描述】:

现在我正在尝试获取我当前的位置,但我只能获取一个位置 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));
}

【问题讨论】:

  • 那个坐标是Googleplex
  • 是的,我知道,但它不是我当前的位置

标签: java android google-maps geolocation


【解决方案1】:

您可能正在模拟器中对此进行测试。它的位置设置为

经度:-122.0840 纬度:37.4220 高度:0.0

默认情况下。

您可以在真实设备上进行测试,也可以在其扩展控件(AVD 旁边的三个点)中为您的虚拟设备配置其他坐标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多