Android GPS获取地理位置并计算距离
2010-06-12 19:52:00 来源:WEB开发网package com.qeesoft.gps;
import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class GPSSpeed extends Activity {
private Location preLocation;
private long preTime;
private static final int step=5000; //msecs
private LocationManager locationManager;
private boolean status=false;
private Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.beginBtn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!status){
status=true;
startLoactionService();
btn.setText("点击这里停止");
}else{
status=false;
stopLocationService();
btn.setText("点击这里开始");
}
}
});
}
public void startLoactionService(){
String serviceName = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(serviceName);
//String provider = LocationManager.GPS_PROVIDER;
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
更多精彩
赞助商链接