How google map fetching address even android device is offline

SARATH V

I just created a map activity with some markers and while click on marker title fetching address of marked position for educational purpose,Everything works fine.

It's fetching address even if device is not connected to internet. I didn't given internet permission in manifest. ACCESS_FINE_LOCATION is the only permission given to the app.

My Question is: How application able to get address even device is in offline mode? What's the idea or technology behind it!!?

Nb: I never used getLastKnownLocation method in my code. Both Wifi and gps off and no sim card inserted.

Here is my code :

    public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    TextView mapPosition;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        mapPosition = (TextView) findViewById(R.id.textplace);

        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
       // double lat = Double.valueOf(8.524139);
        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151); LatLng ind = new LatLng(8.524139, 76.936638);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.addMarker(new MarkerOptions().position(ind).title("Marker in Trivandrum"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(ind));

        mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {






                return false;
            }
        });

    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Geocoder geocoder;
            List<Address> addresses;
            geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());

            try {
                addresses = geocoder.getFromLocation(marker.getPosition().latitude, marker.getPosition().longitude, 1);

                // Here 1 represent max location result to returned, by documents it recommended 1 to 5

                String address = addresses.get(0).getAddressLine(0);
                // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
                String city = addresses.get(0).getLocality();
                String state = addresses.get(0).getAdminArea();
                String country = addresses.get(0).getCountryName();
                String postalCode = addresses.get(0).getPostalCode();
                String knownName = addresses.get(0).getFeatureName();
                String countrycode = addresses.get(0).getCountryCode();

                mapPosition.setText(""+ address);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    }
}
SARATH V

It appears to be cached memory is the answer . I have checked first time with internet, So app stores it cache thats why i still get map loading and getting address of the same lat and lng in device offline.

Code mentioned in the question works fine. Thanks to @pskink.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

having issues fetching google map

分類Dev

Android Google Geofencing transition jumps even device is not moving

分類Dev

Save google map for offline use

分類Dev

How to get the Android device's primary e-mail address

分類Dev

How to check device is Online or Offline Phonegap

分類Dev

How to get IP address of cellular network when device is connected to WiFi in Android

分類Dev

No such device or address

分類Dev

How to find type of device with mac address?

分類Dev

Address Search for the Google Map widget on App Maker

分類Dev

How to set tag to Google Map's marker in Android?

分類Dev

How to manage click on marker which is not in Cluster in Android Google Map API?

分類Dev

How to remove unnecessary marks and places in google map for android app?

分類Dev

How to change Language on Android google map V2 api

分類Dev

Error getting the constant mac address of an android device via the WifiManager

分類Dev

What IP address should I use to connect MySQL with Android Device

分類Dev

Get IP Address used to connect to Firebase from Android device

分類Dev

How to download and use offline maps in Map API V2?

分類Dev

How to map my ipv4 address to external address in iptables

分類Dev

How to check android device codename?

分類Dev

How do you use Processing for Android to display a stereoscopic image in a Google Cardboard device?

分類Dev

Firebase cloud functions on an offline device

分類Dev

Android Google Map API: How to get minimum and maximum coordinate can visible on map

分類Dev

android google maps not loading the map

分類Dev

Make a href which open a Google map with specific address

分類Dev

apt: no such device or address

分類Dev

How to limit Google Places Autocomplete to not include Address?

分類Dev

How to get valid address through @google/maps?

分類Dev

How to solve ADB device unauthorized in Android ADB host device?

分類Dev

How to position Google Map Marker?

Related 関連記事

  1. 1

    having issues fetching google map

  2. 2

    Android Google Geofencing transition jumps even device is not moving

  3. 3

    Save google map for offline use

  4. 4

    How to get the Android device's primary e-mail address

  5. 5

    How to check device is Online or Offline Phonegap

  6. 6

    How to get IP address of cellular network when device is connected to WiFi in Android

  7. 7

    No such device or address

  8. 8

    How to find type of device with mac address?

  9. 9

    Address Search for the Google Map widget on App Maker

  10. 10

    How to set tag to Google Map's marker in Android?

  11. 11

    How to manage click on marker which is not in Cluster in Android Google Map API?

  12. 12

    How to remove unnecessary marks and places in google map for android app?

  13. 13

    How to change Language on Android google map V2 api

  14. 14

    Error getting the constant mac address of an android device via the WifiManager

  15. 15

    What IP address should I use to connect MySQL with Android Device

  16. 16

    Get IP Address used to connect to Firebase from Android device

  17. 17

    How to download and use offline maps in Map API V2?

  18. 18

    How to map my ipv4 address to external address in iptables

  19. 19

    How to check android device codename?

  20. 20

    How do you use Processing for Android to display a stereoscopic image in a Google Cardboard device?

  21. 21

    Firebase cloud functions on an offline device

  22. 22

    Android Google Map API: How to get minimum and maximum coordinate can visible on map

  23. 23

    android google maps not loading the map

  24. 24

    Make a href which open a Google map with specific address

  25. 25

    apt: no such device or address

  26. 26

    How to limit Google Places Autocomplete to not include Address?

  27. 27

    How to get valid address through @google/maps?

  28. 28

    How to solve ADB device unauthorized in Android ADB host device?

  29. 29

    How to position Google Map Marker?

ホットタグ

アーカイブ