Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is my solution :</p> <pre><code>private void createMarkerWithLocation() { /* Use the LocationManager class to obtain GPS locations */ LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300000, 40, this); Location location = mlocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); /*check both providers even for lastKnownLocation*/ if (location == null) location = mlocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); LatLng currentLatLng = new LatLng(latitude, longitude); if(isConnected(this)) { Geocoder gCoder = new Geocoder(ChoiceDestinationActivity.this); List&lt;Address&gt; addresses = gCoder.getFromLocation(latitude, longitude, 1); String address = addresses.get(0).getAddressLine(0); String city = addresses.get(0).getAddressLine(1); String country = addresses.get(0).getAddressLine(2); Toast.makeText(this, country + ", " + city + ", " + address, Toast.LENGTH_SHORT).show(); marker = map.addMarker(new MarkerOptions() .position(currentLatLng) .title(city) .snippet(address) .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))); } } } public static boolean isConnected(Context context) { NetworkInfo ni = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); return (ni!=null &amp;&amp; ni.isAvailable() &amp;&amp; ni.isConnected()); } </code></pre> <p>I use it to add a marker on google map. It allows you to retrieve all the information regarding the location of the user.</p> <p>I hope you have helped!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload