You need to use the variable "location" passed into onLocationChanged.
Right now, you're ignoring it.
On Thursday, August 9, 2012 7:13:16 AM UTC-5, Ece Osmanağaoğlu wrote:
>
> I added LocationListener, unfortunately still doesn't work.
>
> locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
> gpsProv = locMan.GPS_PROVIDER;
> locMan.requestLocationUpdates(gpsProv, 0, 0, locList);
>
> okullar.setOnItemClickListener(new OnItemClickListener()
> {
> public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
> long arg3)
> {
> AlertDialog.Builder alert = new
> AlertDialog.Builder(Kampusler.this);
> switch (arg2)
> {
> case 0:
> alert.setTitle("- Konumunuz
> -").setMessage(Lokasyonum()).setPositiveButton("Tamam", null).show();
> break;
>
> case 1:
> alert.setTitle("- Konumunuz
> -").setMessage(Lokasyonum()).setPositiveButton("Tamam", null).show()
> break;
> default:
> break;
> }
> }
> });
> }
> private String Lokasyonum()
> {
> loc = locMan.getLastKnownLocation(gpsProv);
> if(loc != null)
> MyLocation();
> else
> Toast.makeText(getApplicationContext(), "Can't Find...",
> Toast.LENGTH_SHORT).show();
>
> return sonuc;
> }
>
> private String MyLocation()
> {
> Geocoder myGeo = new Geocoder(Kampusler.this);
> try
> {
> List<Address> adres = myGeo.getFromLocation(loc.getLatitude(),
> loc.getLongitude(), 1);
> if(adres != null)
> {
> for(int i=0; i<adres.get(0).getMaxAddressLineIndex(); i++)
> {
> sonuc = adres.get(0).getAddressLine(i) + "\n";
>
> }
> }
> else
> Toast.makeText(getApplicationContext(), "Can't Find
> Address...", Toast.LENGTH_SHORT).show();
> }
> catch (Exception e)
> {
> e.printStackTrace();
> Toast.makeText(getApplicationContext(), e.getMessage(),
> Toast.LENGTH_SHORT).show();
> }
>
> return sonuc;
> }
>
> public class MyLocList implements LocationListener
> {
> public void onLocationChanged(Location location)
> {
> MyLocation();
> }
> public void onProviderDisabled(String provider)
> {}
> public void onProviderEnabled(String provider)
> {}
> public void onStatusChanged(String provider, int status,
> Bundle extras)
> {}
> }
> }
> On Wednesday, August 8, 2012 3:13:26 PM UTC+3, Ece Osmanağaoğlu wrote:
>>
>> I wanna get current location.
>> There is null pointer exception in List<Address>
>>
>> locMan = (LocationManager)
>> this.getSystemService(Context.LOCATION_SERVICE);
>> gpsProv = LocationManager.GPS_PROVIDER;
>> locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000,
>> 250, Kampusler.this);
>> myGeo = new Geocoder(Kampusler.this, Locale.getDefault());
>>
>> loc = locMan.getLastKnownLocation(gpsProv);
>> try
>> {
>> List<Address> adres =
>> myGeo.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
>> if(adres != null)
>> {
>> for(int i=0; i <
>> adres.get(0).getMaxAddressLineIndex(); i++)
>> {
>> result += adres.get(0).getAddressLine(i) + "\n";
>> }
>> }
>> else
>> {
>> Toast.makeText(Kampusler.this, "Don't get
>> address...", Toast.LENGTH_LONG).show();
>> }
>> }
>> catch (Exception e)
>> {
>> e.printStackTrace();
>> Toast.makeText(getApplicationContext(), e.getMessage(),
>> Toast.LENGTH_SHORT).show();
>> }
>>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en