Geolocalisation sous android
Bonjour à tous,
Je cherche à faire une petite application qui localisera le pays dans lequel on se trouve (avec l'adresse si possible et le code du pays).
Pour cela j'ai suivi un tutoriel sur la localisation et j'arrive au code suivant:
Code:
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);
}
}
} |
Comme vous pouvez le voir, le code contient de nombreuses erreurs que je ne parviens pas à résoudre seul. Un peu d'aide serait plus que le bienvenue :)
Les erreurs se trouvent aux lignes suivantes:
40 à 47
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);
57 à60
ArrayList<LocationProvider> providers = new ArrayList<LocationProvider>();
ArrayList<String> names = locationManager.getProviders(true);
for (String name : names)
providers.add(locationManager.getProvider(name));
68
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 150, new LocationListener() {
90 à 92
Intent intent = new Intent(this, GPSUpdateReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
locationManager.requestLocationUpdates(provider,60000,150,pending);