• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Gps xy coordinates

i have error in below bold code please help me how to rectifies these errors;

package com.gps;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class UseGpsActivity extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);



LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

LocationListener mlocListener = new MyLocationListener();

mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

}

/* Class My Location Listener */

public class MyLocationListener implements LocationListener

{

public void onLocationChanged(Location loc)

{

loc.getLatitude();

loc.getLongitude();

String Text =
 
1) Please use code brackets to show code, instead of placing code in long, incorrectly formatted post.

2) in order to use a string like that as an argument, you must explicitly declare it as such. ((String) "Some Text") See line 39 and 43.

3) Another alternative is to declare your String variable as an empty string, as done in line 31 and THEN concatenate it with whatever you want (lines 32-34).

Code:
package com.gps;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;

public class UseGpsActivity extends Activity
{
  /** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener mlocListener = new MyLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
  }

  /* Class My Location Listener */

  public class MyLocationListener implements LocationListener
  {
    public void onLocationChanged(Location loc) {
      loc.getLatitude();
      loc.getLongitude();
      String text = "";
      text += "My current location is: \n";
      text += "Latitud = " + loc.getLatitude() + "\n";
      text += "Longitud = " + loc.getLongitude();
      Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }

    public void onProviderDisabled(String provider) {
      Toast.makeText( getApplicationContext(), ((String) "GPS Disabled"), Toast.LENGTH_SHORT ).show();
    }

    public void onProviderEnabled(String provider) {
      Toast.makeText( getApplicationContext(), ((String) "GPS Enabled"), Toast.LENGTH_SHORT).show();
    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
  }
}
 
Back
Top Bottom