wang_peng1 发表于 2013-1-28 18:56:20

Gps简单更新

package gps.test; 
 
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 GPS extends Activity { 
private LocationManager lm; 
private LocationListener locationListener; 
 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
 
    // ---use the LocationManager class to obtain GPS locations--- 
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
 
    locationListener = new MyLocationListener(); 
 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, 
            locationListener); 

 
private class MyLocationListener implements LocationListener { 
    @Override 
    public void onLocationChanged(Location loc) { 
        if (loc != null) { 
            Toast.makeText( 
                    getBaseContext(), 
                    "Location changed : Lat: " + loc.getLatitude() 
                            + " Lng: " + loc.getLongitude(), 
                    Toast.LENGTH_SHORT).show(); 
        } 
    } 
 
    @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 
    } 


你一定记得要移动一下啊,不过最好还是设置一下参数 该成1秒1000 另一个为0也可以
页: [1]
查看完整版本: Gps简单更新