【问题标题】:Android google map not exact coordinatesAndroid 谷歌地图不是精确的坐标
【发布时间】:2015-12-22 20:33:20
【问题描述】:

您好,我正在开发自己的地图定位器。但它没有给出确切的坐标。我已经尝试使用谷歌地图来定位我的当前位置,它为我提供了我所在位置的正确位置。

在谷歌地图应用程序中

但在我的应用程序上

我不知道为什么我的应用程序没有像 GOOGLE MAP 应用程序那样给我准确的位置。

我错过了什么吗? 这是我的谷歌地图初始化

` int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        } else { // Google Play Services are available

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fgmMain);

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map
            googleMap.setMyLocationEnabled(false);

            // Getting LocationManager object from System Service LOCATION_SERVICE
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

            // Creating a criteria object to retrieve provider
            Criteria criteria = new Criteria();

            // Getting the name of the best provider
            String provider = locationManager.getBestProvider(criteria, true);

            // Getting Current Location
            Location location = locationManager.getLastKnownLocation(provider);

            if (location != null) {

                LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());

                googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

                // Zoom in the Google Map
                googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));


                // Setting latitude and longitude in the TextView tv_location
                db = new DatabaseHandler(context);
                DBUser duser = db.getUser().get(0);

                Marker mark = googleMap.addMarker(new MarkerOptions()
                                .position(latLng)
                                .title(duser.get_name() + " - " + Build.MODEL)
                                .snippet("Location: " + latLng.toString() + " @ " + gTime)
                                .icon(BitmapDescriptorFactory.fromBitmap(MapIcon("myphone")))
                                .anchor(0.5f, verticalAnchor)
                );

                Log.d("Current Location", latLng.toString());

                onLocationChanged(location);
            }

        }`

清单 XML `

<uses-permission android:name="com.package.phonelocate.phonelocator.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

` 我可以得到与谷歌地图应用程序相同的结果吗?

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    这应该可行:

    googleMap.setMyLocationEnabled(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      相关资源
      最近更新 更多