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

Apps Gps locator errors

Bold line in this coding have errors at the time of running, please give me the solution for that.

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.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GpsLocationActivity extends Activity {
protected static final TextView et_field_name = null;
/** Called when the activity is first created. */
public static double latitude;
public static double longitude;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn_show_location= (Button)findViewById(R.id.button1);


public class MyLocationListener implements LocationListener {

public static double latitude;
public static double longitude;
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
latitude=loc.getLatitude();
longitude=loc.getLongitude();
}
public void onProviderDisabled(String provider)
{
//print "Currently GPS is Disabled";
}
public void onProviderEnabled(String provider)
{
//print "GPS got Enabled";
}

public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
btn_show_location.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
LocationManager mlocManager=null;
LocationListener mlocListener;
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if(MyLocationListener.latitude>0)
{
et_field_name.append("Latitude:- " + MyLocationListener.latitude + '\n');
et_field_name.append("Longitude:- " + MyLocationListener.longitude + '\n');
}
else
{
alert.setTitle("Wait");
alert.setMessage("GPS in progress, please wait.");
alert.setPositiveButton("OK", null);
alert.show();

}
} else {
et_field_name.setText("GPS is not turned on...");
}

}
});
}
}
 
For one, you don't have alert declared anywhere, let alone defined.

Also, can you please put your code in
Code:
 tags? It makes it much easier to read as it retains the proper formatting.
 
<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.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GpsLocationActivity extends Activity {
protected static final TextView et_field_name = null;
/** Called when the activity is first created. */
public static double latitude;
public static double longitude;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn_show_location= (Button)findViewById(R.id.button1);


public class MyLocationListener implements LocationListener {

public static double latitude;
public static double longitude;
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
latitude=loc.getLatitude();
longitude=loc.getLongitude();
}
public void onProviderDisabled(String provider)
{
//print "Currently GPS is Disabled";
}
public void onProviderEnabled(String provider)
{
//print "GPS got Enabled";
}

public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
btn_show_location.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
LocationManager mlocManager=null;
LocationListener mlocListener;
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
if(MyLocationListener.latitude>0)
{
et_field_name.append("Latitude:- " + MyLocationListener.latitude + '\n');
et_field_name.append("Longitude:- " + MyLocationListener.longitude + '\n');
}
else
{
alert.setTitle("Wait");
alert.setMessage("GPS in progress, please wait.");
alert.setPositiveButton("OK", null);
alert.show();
}
} else {
et_field_name.setText("GPS is not turned on...");
}

}
});
}
}


</code>
 
BOLDED LETTERS SHOWS ERRORS PLZ RECTIFIES THAT, IF YOU HAVE SOURCE CODE FOR WIFI BASED LOCATION IDENTIFIER PLEASE POST TO MY MAIL seetharam1000@gmail.com



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.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GpsLocationActivity extends Activity {
    protected static final TextView et_field_name = null;
    /** Called when the activity is first created. */
     public static double latitude;
     public static double longitude;
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn_show_location= (Button)findViewById(R.id.button1);
       
    
        public class MyLocationListener implements LocationListener {
            
                    public static double latitude;
                    public static double longitude;
                    public void onLocationChanged(Location loc)
                    {
                        loc.getLatitude();
                        loc.getLongitude();
                        latitude=loc.getLatitude();
                        longitude=loc.getLongitude();
                    }
                    public void onProviderDisabled(String provider)
                    {
                        //print "Currently GPS is Disabled";
                    }
                    public void onProviderEnabled(String provider)
                {
                        //print "GPS got Enabled";
                    }
                
                    public void onStatusChanged(String provider, int status, Bundle extras)
                    {
                    }
                }
        btn_show_location.setOnClickListener(new View.OnClickListener() {
            
                 public void onClick(View view) {
                         LocationManager mlocManager=null;
                         LocationListener mlocListener;
                     mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                     mlocListener = new MyLocationListener();
                        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
                 
                        if (mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                            if(MyLocationListener.latitude>0)
                            {
                                 et_field_name.append("Latitude:- " + MyLocationListener.latitude + '\n');
                                 et_field_name.append("Longitude:- " + MyLocationListener.longitude + '\n');
                             }
                             else
                             {
                                  [B]alert[/B].setTitle("Wait");
                                  [B]alert[/B].setMessage("GPS in progress, please wait.");
                                  [B]alert[/B].setPositiveButton("OK", null);
                                  [B]alert[/B].show();
                              }
                          } else {
                              [B]et_field_nam[/B]e.setText("GPS is not turned on...");
                          }
                 
                      }
                 });
    }
}
 
1) use
Code:
 not <code>. It's formatted using BBCODE not HTML.

2) posting in caps and repeatedly posting the same message will not get you anywhere. In fact, people will be less likely to reply as it will annoy them.

3) does it even run? From looking at your code, it would seem that you don't have the alert object or the et_field_name object declared anywhere, so it shouldn't even compile, let alone run. If it doesn't compile and you are using some IDE (i.e. Eclipse), it should put a red squiggly line under those objects, and if you hold your mouse over the lines for a second, it will show you what is wrong and (assuming you are using Eclipse) give you some options to automatically fix it.
 
Back
Top Bottom