in this code location listener will be re instantiated each time you
close and open your app...so if an onLocationChanged(Location loc)
triggers you'll be executing everything in this method n-times it was
instantiated.
so you'll have to "check" this doesn't happen by code...
you can try this adding this lines:
public void onLocationChanged(Location loc) {
// Called when the location has changed.
Log.d("newlocation", "===>>> onLocationChanged");
if (loc != null) {
Toast.makeText(
getBaseContext(),
"Location changed : Lat: " +
loc.getLatitude()
+ " Lng: " +
loc.getLongitude(),
Toast.LENGTH_SHORT).show();
}
I was testing this some minutes ago. Anyone with the same problem?
On Nov 27, 11:43 am, "salman.geek" <[EMAIL PROTECTED]> wrote:
> I think the Following Code Snippent may help you but you have to send
> the Latitute and Longitude using DDMS view FOr that....
> Here comes the code for Android SDK 1.0
>
> package com.gps;
>
> import android.content.Context;
> import android.location.Location;
> import android.location.LocationListener;
> import android.location.LocationManager;
> import android.os.Bundle;
> import android.widget.TextView;
>
> import com.google.android.maps.MapActivity;
> public class Gps extends MapActivity {
> private LocationManager lm;
> private LocationListener locationListener;
>
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
> // ---use the LocationManager class to obtain GPS locations---
> lm = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
>
> locationListener = new MyLocationListener();
>
> lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
> locationListener);
>
> setContentView(R.layout.main);
>
> }
>
> @Override
> protected boolean isRouteDisplayed() {
> // TODO Auto-generated method stub
> return false;
> }
>
> private class MyLocationListener implements LocationListener {
> @Override
> public void onLocationChanged(Location loc) {
> if (loc != null) {
> TextView tv = (TextView)
> findViewById(R.id.lat);
> TextView tv2 = (TextView)
> findViewById(R.id.longitude);
> tv.setText(" --- > " + loc.getLatitude());
> tv2.setText(" --- > " + loc.getLongitude());
>
> }
> }
>
> @Override
> public void onProviderDisabled(String provider) {
> // TODO Auto-generated method stub
> }
>
> @Override
> public void onProviderEnabled(String provider) {
> // TODO Auto-generated method stub
> }
>
> @Override
> public void onStatusChanged(String provider, int status,
> Bundle
> extras) {
> // TODO Auto-generated method stub
> }
> }
>
> }
>
> I think you will create the Resources for that...This code will show
> you your current Latitude and Longitude...
> Regards
> Salman Khursheed
>
> On Nov 27, 7:36 pm, Peterman <[EMAIL PROTECTED]> wrote:
>
> > Me too....
>
> > On Oct 22, 2:47 am, BarbieDahl <[EMAIL PROTECTED]> wrote:
>
> > > Hello Everyone,
>
> > > I am trying to use Androidslocationbasedservicesand I was
> > > wondering if there are code samples available that show how to plot
> > > points from a .kml or .gpx file on a map. I have found many examples
> > > using m5 but nothing for m9 or release 1.0. Can someone help me?- Hide
> > > quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---