Всего за несколько месяцев до Google освободить новый и простой api для прослушивания местоположения.
Это просто с несколькими строками кода.
Поясню
Шаг 1: Скачать Google играть библиотеку Service с помощью SDK manager.Because Расположение службы подключения к Google играть.
Шаг 2: Импорт библиотеки в рабочем пространстве
Шаг 3: Добавить библиотеку в проект
шаг 4: написать следующий код.
public class MainActivity extends Activity {
LocationClient mlocationclient;
Location location;
LocationRequest mlocationrequest;
int trasition_type=Geofence.GEOFENCE_TRANSITION_ENTER;
LocationListener mlistener;
PendingIntent lviolation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int isGooglePlayServiceAvilable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (isGooglePlayServiceAvilable == ConnectionResult.SUCCESS) {
//Create the location client
mlocationclient=new LocationClient(getApplicationContext(), new CallBack(), new ConnectError());
mlocationclient.connect();
//create the location request objetcs..
mlocationrequest=LocationRequest.create().setInterval(1000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
//Crearte the location listener when we want to get location.
mlistener=new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.i("Mine Location", ""+location);
}
};
public class ConnectError implements GooglePlayServicesClient.OnConnectionFailedListener
{
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
}
}
public class CallBack implements GooglePlayServicesClient.ConnectionCallbacks
{
@Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
location=mlocationclient.getLastLocation();
mlocationclient.requestLocationUpdates(mlocationrequest, mlistener);
//new GetAddress(getApplicationContext()).execute(location);
}
}
Шаг 5: Поместите этот код в файле манифеста андроида
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>`
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
что вы прочитали о плавленом провайдере местоположения вы можете предоставить любую документацию , пожалуйста –
Я читал эти ссылки: http://thenextweb.com/google/2013/05/16/inside-googles-new-location-apis-for-android/ и http: //www.kpbird. com/2013/06/fused-location-provider-example.html – Arsalan
спасибо yar .... –