@@ -301,10 +301,87 @@ dbHelper.getRecordCount(tableName, values, hasConditions, conditionalValues);
301301 app : typeface =" QuattrocentoSans-Regular.ttf" />
302302```
303303
304- ### ToastMsg
304+ ### Location
305305
306- > ** If you want to use a custom toast message then you can use this class.**
306+ > ** This class will get the current location of the user.**
307+ ``` java
308+ // Declare this class globally inside your activity or class.
309+ private double latitude = 0.0 , longitude = 0.0 ;
310+ private MyLocation myLocation = new MyLocation ();
307311
312+ // Use myLocation's class's Location listener which will return latitude and longitude of current location.
313+ private MyLocation . LocationResult locationResult = new Mylocation .LocationResult ()
314+ {
315+ @Override
316+ public void gotLocation(Location location)
317+ {
318+ try
319+ {
320+ latitude = location. getLatitude();
321+ longitude = location. getLongitude();
322+
323+ Log . e(TAG , " gotLocation: Latitude of the location is: " + latitude);
324+ Log . e(TAG , " gotLocation: Longitude of the location is: " + longitude);
325+ }
326+ catch (Exception e)
327+ {
328+ Log . e(TAG , " gotLocation: exception while getting location lat, long:\n " );
329+ e. printStackTrace();
330+ }
331+ }
332+ };
333+
334+ // all the above code should be used globally.
335+ // now use the myLocation's class's object as below inside onCreate method.
336+ myLocation. getLocation(this , locationResult);
308337```
309338
339+ ### Location Address
340+
341+ > ** This class helps your to get the address of the current location or by using latitude and longitude.**
342+ ``` java
343+ // use the following code to get the address of the latitude and longitude.
344+ // declare this inside onCreate() method or anywhere you would like to use it.
345+ // on button click or anywhere.
346+
347+ LocationAddress . getAddressFromLocation(
348+ mLatitude, mLongitude, this ,
349+ new GeocoderHandler ());
350+
351+
352+ // this is the GeocoderHandler class where you'll get the address
353+ private class GeocoderHandler extends Handler
354+ {
355+ @Override
356+ public void handleMessage (Message msg )
357+ {
358+ switch (msg. what)
359+ {
360+ case 1 :
361+
362+ Bundle bundle = msg. getData();
363+
364+ // note that subThoroughFare may return null sometimes.
365+ String address = bundle. getString(" subThoroughFare" ) + " , " +
366+ bundle. getString(" thoroughFare" );
367+
368+ String subLocality = bundle. getString(" subLocality" );
369+ String subAdminArea = bundle. getString(" subAdminArea" );
370+ String postalCode = bundle. getString(" postalCode" );
371+
372+ String city = bundle. getString(" city" );
373+ String state = bundle. getString(" state" );
374+ String country = bundle. getString(" country" );
375+
376+ break ;
377+
378+ default :
379+
380+ // address not found.
381+
382+ break ;
383+ }
384+ }
385+ }
310386```
387+
0 commit comments