Android GPS cloud confusion!

I am trying to create my first GPS Android app. At the moment, I have a button that can be clicked when you click the "Warning" button for the appearance of longitude and latitude. I tried using telnet localhost 5554 and then geo fix #number #number to enter values, but the results are not displayed only 0 0. I also tried the DDMS way to send GPS coordinates, and I get the same.

My question is what exactly is the correct way to use geo fix and how to send DDMS coordinates. I have used Location, LocationMangerand LocationListener, but I'm not sure this is the right choice.

The code is indicated, just in case an error exists with the code

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button = (Button) findViewById(R.id.track);
    button.setOnClickListener(this);
    LocationManager location =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location loc = location.getLastKnownLocation(location.GPS_PROVIDER);
    updateWithNewLocation(loc);

  }

 private final LocationListener locationListener = new LocationListener() {
   public void onLocationChanged(Location location) {
     updateWithNewLocation(location);
   }

  private void updateWithNewLocation(Location l) {
  longitude = l.getLongitude();
  latitude = l.getLatitude();
  provider = l.getProvider();     
  }

    public void onClick(View v) { 
     Toast.makeText(this, "Your location is " + 
      longitude + " and " + latitude + " provided by: " + 
      provider, Toast.LENGTH_SHORT).show();          
   }     
}
+3
2

1)

2) GPS

location.requestLocationUpdates(LocationManager.GPS, 100, 1, locationListener);

, locationListener.

Android GPS: http://www.devx.com/wireless/Article/43005

(! DevX , !)

+3

  loc = location.getLastKnownLocation(location.GPS_PROVIDER);

, gps ddms

, , loc = location.getLastKnownLocation( "gps" );

+1

Source: https://habr.com/ru/post/1719936/


All Articles