location
Location Based Services Application
With this example we are going to create a location based services application for Android. Location Based Services are quite popular on mobiles nowadays.
To create a location based services application one should perform the following steps:
- Create an Android Activity (here called LbsGeocodingActivity)
- Get reference of the LocationManager system service
- Use the requestLocationUpdates method of LocationManager
- Implement the LocationListener interface and handle location updates
- Implement the desired functionality inside the onStatusChanged method
These are demonstrated in the code snippet(s) below:
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | package com.javacodegeeks.android.lbs; import android.app.Activity; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class LbsGeocodingActivity extends Activity { private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1 ; // in Meters private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000 ; // in Milliseconds protected LocationManager locationManager; protected Button retrieveLocationButton; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, new MyLocationListener() ); retrieveLocationButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { showCurrentLocation(); } }); } protected void showCurrentLocation() { Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null ) { String message = String.format( "Current Location n Longitude: %1$s n Latitude: %2$s" , location.getLongitude(), location.getLatitude() ); Toast.makeText(LbsGeocodingActivity. this , message, Toast.LENGTH_LONG).show(); } } private class MyLocationListener implements LocationListener { public void onLocationChanged(Location location) { String message = String.format( "New Location n Longitude: %1$s n Latitude: %2$s" , location.getLongitude(), location.getLatitude() ); Toast.makeText(LbsGeocodingActivity. this , message, Toast.LENGTH_LONG).show(); } public void onStatusChanged(String s, int i, Bundle b) { Toast.makeText(LbsGeocodingActivity. this , "Provider status changed" , Toast.LENGTH_LONG).show(); } public void onProviderDisabled(String s) { Toast.makeText(LbsGeocodingActivity. this , "Provider disabled by the user. GPS turned off" , Toast.LENGTH_LONG).show(); } public void onProviderEnabled(String s) { Toast.makeText(LbsGeocodingActivity. this , "Provider enabled by the user. GPS turned on" , Toast.LENGTH_LONG).show(); } } } |
This was an example of an Android location based services application.
Related Article:
http://www.aiobjectives.com
worldwide.Technology, especially artificial intelligence
has made our lives really easy. From the general apps to
Alexa in our houses technology has seeped in even without
us realizing when this happened. Here is a quick view of
future where AI will have significant role in each phase
of our life.
Android is a mobile operating system based on a modified
version of the Linux kernel and other open source software,
designed primarily for touchscreen mobile devices such as
smartphones and tablets. … These apps are licensed by
manufacturers of Android devices certified under
imposed by Google
Alarming challange: white collar machines and Artifical intelligence.
and what is the futuer if collar machines and Artifical intelligence.