public class MainActivity extends Activity implements OnClickListener {
private String keyString = "c2BByoQymlA1C75PGmG";
private Button mButton;
private String mPhone;
public TextView locationInfoTextView = null;
public LocationClient mLocationClient = null;
private static int LOCATION_COUTNS = 0;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
mLocationClient = new LocationClient (getApplicationContext ());
mLocationClient.setAK (keyString);
locationInfoTextView = (TextView) findViewById (R.id.textView2);
mButton = (Button) findViewById (R.id.button1);
. mPhone = findViewById (R.id.editText1) toString ();
LocationClientOption option = new LocationClientOption ();
option.setOpenGps (true);
option.setAddrType ("all") ;/ / positioning results returned contain address information
option.setCoorType ("bd09ll") ;/ / positioning results returned is Baidu latitude and longitude, the default value gcj02
option.setScanSpan (5000) ;/ / set the interval to initiate positioning request to 5000ms
option.disableCache (true) ;/ / enable caching positioning
banoption.setPoiNumber (5); / / returns the maximum number of
POIoption.setPoiDistance (1000); / / poi inquiries from
option.setPoiExtraInfo (true); details / / if need POI phone number and address
mLocationClient.setLocOption (option);
mLocationClient.registerLocationListener (new BDLocationListener () {
@ Override
public void onReceivePoi (BDLocation location) {
/ / TODO Auto-generated method stub
if (location == null) {
return;
}
StringBuffer sb = new StringBuffer (256);
sb.append ("Poi time:");
sb.append (location.getTime ());
sb.append ("\ nerror code:");
sb.append (location.getLocType ());
sb.append ("\ nlatitude:");
sb.append (location.getLatitude ());
sb.append ("\ nlontitude:");
sb.append (location.getLongitude ());
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 ());
}
LOCATION_COUTNS + +;
sb.append ("\ n punch number:");
sb.append (String.valueOf (LOCATION_COUTNS));
System.err.println ("running into this a");
locationInfoTextView.setText (sb.toString ());
logMsg (sb.toString ());
}
@ Override
public void onReceiveLocation (BDLocation arg0) {
/ / TODO Auto-generated method stub
}
});
mButton.setOnClickListener (this);
}
@ Override
public void onClick (View v) {
/ / TODO Auto-generated method stub
mLocationClient.start ();
}
private void logMsg (String string) {
/ / TODO Auto-generated method stub
if (TextUtils.isEmpty (string) | | TextUtils.isEmpty (mPhone)) {
Toast.makeText (MainActivity.this, R.string.success,
. Toast.LENGTH_LONG) show ();
} Else {
/ / GetDefault () is to get sms instance
SmsManager mSmsManager = SmsManager.getDefault ();
/ / DivideMessage () is the decomposition of a single SMS message so that the content does not exceed the defined limit
Collections / / convenience decomposition obtained send all content
ArrayList
for (String str: mContents) {
mSmsManager.sendTextMessage (mPhone, null, string, null, null);
}
}
}
@ Override
protected void onDestroy () {
super.onDestroy ();
if (mLocationClient! = null && mLocationClient.isStarted ()) {
mLocationClient.stop ();
mLocationClient = null;
}
}
}
How does not return information ah
Reply:
Network and GPS permissions to open, and then get the GPS is sometimes visible, especially in places with poor signal.
No comments:
Post a Comment