1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| package com.mathieu.emergency;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
public class MapsActivity extends FragmentActivity {
Button Badresse, Bappel;
TextView Tadresse, Tcountry;
EditText adresse, country;
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Badresse = (Button) findViewById(R.id.badresse);
Bappel = (Button) findViewById(R.id.bappel);
Tadresse = (TextView) findViewById(R.id.Tadresse);
Tcountry = (TextView) findViewById(R.id.Tcountry);
adresse = (EditText) findViewById(R.id.adresse);
country = (EditText) findViewById(R.id.country);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
protected void afficheradresse(View v) {
ArrayList<LocationProvider> providers = new ArrayList<LocationProvider>();
ArrayList<String> names = locationManager.getProviders(true);
for (String name : names)
providers.add(locationManager.getProvider(name));
Criteria critere = new Criteria();
critere.setAccuracy(Criteria.ACCURACY_FINE);
critere.setBearingRequired(true);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 150, new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
Log.d("GPS", "Latitude " + location.getLatitude() + " et longitude " + location.getLongitude());
}
Intent intent = new Intent(this, GPSUpdateReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
locationManager.requestLocationUpdates(provider,60000,150,pending);
});
}
public class GPSUpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Location location = (Location)intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED);
}
}
} |
Partager