简体   繁体   中英

Android Google Maps show location without internet

I am using SupportMapFragment and when I use GoogleMap with Internet it is easy to show blue point from GoogleMaps Android to show my location and zoom camera to it, but when my app is in offline mode but location is on I can easily zoom to my location but can't show that blue point.

if (mGoogleMap != null) { List<RestaurantDTO> local = new ArrayList<>(); local.addAll(mRestData); mGoogleMap.setInfoWindowAdapter(new RestaurantAdapter()); mGoogleMap.setMyLocationEnabled(true); mGoogleMap.getMyLocation(); mGoogleMap.getFocusedBuilding();

So here I think main mGoogleMap.setMyLocationEnabled(true); and mGoogleMap.getMyLocation(); methods so that when I delete then it doesn't show my blue circle pin.

Map doesn't cache anything, you need to check if you have internet connection and set location source

 if (!CommonUtils.isHasInternetConnection(mCtx)) {    .icon(BitmapDescriptorFactory.fromResource(R.drawable.blue_google_maps_img)));
                LocationSource source = new LocationSource() {
                    @Override
                    public void activate(OnLocationChangedListener onLocationChangedListener) {
                        Location location = new Location("myProvider");
                        location.setLatitude(mCurrLatLng.latitude);
                        location.setLongitude(mCurrLatLng.longitude);
                        onLocationChangedListener.onLocationChanged(location);
                    }

                    @Override
                    public void deactivate() {
                    }
                };
                mGoogleMap.setLocationSource(source);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM