location

public class Location extends Application {
public LocationClient mLocationClient = null;
private String mData;
public MyLocationListenner myListener = new MyLocationListenner();
TextView mTv;

public void onCreate()
{
mLocationClient = new LocationClient(this);
mLocationClient.registerLocationListener(myListener);
}
/**
* @param str
*/
public void logMsg(String str)
{
    Log.v("system", "location value is:"+str);
try
{
mData = str;
if ( mTv != null )
{
    mTv.setText(mData);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

/**
* 返回结果处理
*/
public class MyLocationListenner implements BDLocationListener
{
public void onReceiveLocation(BDLocation location)
{
if (location == null)
{
    return ;
}
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(((Double)location.getLatitude()).longValue());
sb.append("\nlontitude : ");
sb.append(((Double)location.getLongitude()).longValue());
sb.append("\nradius : ");
sb.append(location.getRadius());
if (location.getLocType() == BDLocation.TypeGpsLocation)
{
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
}
else if (location.getLocType() == BDLocation.TypeNetWorkLocation)
{
sb.append("\naddr : ");
sb.append(location.getAddrStr());
}
/**
* 写值处理
*/
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("time", location.getTime());
parameters.put("latitude", ""+location.getLatitude());
parameters.put("longitude", ""+location.getLongitude());
parameters.put("locType", ""+location.getLocType());
parameters.put("speed", ""+location.getSpeed());
parameters.put("satelliteNumber", ""+location.getSatelliteNumber());
parameters.put("address", location.getAddrStr());
parameters.put("radius", ""+location.getRadius());
PropertiesOperation.writeProperties(Parameters.LOCATION_PATH,parameters);;

logMsg(sb.toString());
}
}

你可能感兴趣的:(location)