Android谷歌地图不精确坐标

时间:2015-12-20 09:49:06

标签: android google-maps

您好我正在开发自己的地图定位器。但它并没有给出精确的坐标。我已经尝试使用谷歌地图找到我当前的位置,它给了我正确的位置。

在Google地图应用中 enter image description here

但在我的应用程序上 enter image description here

我不知道为什么我的申请没有给我确切的位置作为GOOGLE MAP App。

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

`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" />

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

1 个答案:

答案 0 :(得分:0)

这应该有效:

googleMap.setMyLocationEnabled(true);