Here is my code, I want to get after their geographical location, are displayed in the text domain, but the method is called requestLocation Each time the return value is 1, the location service does not start, please help me find Great God
mLocationClient = new LocationClient (this); / / declare LocationClient class mLocationClient.registerLocationListener (myListener); / / Register the listener function LocationClientOption option = new LocationClientOption (); option.setOpenGps (true); option.setAddrType ("detail"); option.setCoorType ("gcj02"); option.setScanSpan (5000); option.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.start ();
}
public void getPositionInfo (View view) { if (mLocationClient! = null && mLocationClient.isStarted ()) mLocationClient.requestLocation (); else Log.d ("LocSDK_2.0_Demo1", "locClient is null or not started"); }
private class MyLocationListener implements BDLocationListener {
@ Override public void onReceiveLocation (BDLocation location) {
@ Override public void onReceivePoi (BDLocation arg0) { / / TODO Auto-generated method stub
}}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: Baidu Maps Demo official suggestion you download to see Reply: Solved yet landlord? I also encountered the same problem Reply:
You configure the service in the manifest file it? I just did not configure the service. . . Reply: Configuration that it? When I configured it can not successfully start ah Reply: locationClient = new LocationClient (getApplicationContext ()); Put your this to getApplicationContext () on the line. Reply: Put this to getApplicationContext (), but still not hey. . Who will help ah. Reply:
Code is no problem, my problem is in the service of this component is not configured in the configuration file Reply: I have configured, and also returns 1. Later found not start, see if you do not start Reply:
Thank you, this way she can. However, I still do not understand a bit: Engineering (1) I do the test is used, there is only one MainActivity when I use this, to successfully obtain location information, Engineering (2) there are multiple Activity, obtain location information The Activity is not MainActivity. Then again this could not get to, but changed getApplicationContext () successfully access to the location information ... What is the reason? I hope you can answer ... Thanks again! Reply:
Encounter with the main layer is consistent, adjusting the twelve days the rub ... Figure out the problem yet? I looked under the getApplicationContext (), and this difference, about the life cycle, but did not understand Reply:
locationClient = new LocationClient (getApplicationContext ()); Put your this to getApplicationContext () on the line.
Thank you, this way she can. However, I still do not understand a bit: Engineering (1) I do the test is used, there is only one MainActivity when I use this, to successfully obtain location information, Engineering (2) there are multiple Activity, obtain location information The Activity is not MainActivity. Then again this could not get to, but changed getApplicationContext () successfully access to the location information ... What is the reason? I hope you can answer ... Thanks again!
Baidu Class Reference inside wrote: public LocationClient (Context) / / must be declared in the main thread Is a relationship with this, this is not the main thread? Reply: This should be done only when an Activity, which this is the main thread, and when I do have multiple Activity when the Activity is another entrance, that is, at this time and then this, it is not in the main the thread ... do not know is not like that, so I do understand it first, if you have any good explanation, Could you tell me ... thank you! Reply:
locationClient = new LocationClient (getApplicationContext ()); Put your this to getApplicationContext () on the line.
Thank you, this way she can. However, I still do not understand a bit: Engineering (1) I do the test is used, there is only one MainActivity when I use this, to successfully obtain location information, Engineering (2) there are multiple Activity, obtain location information The Activity is not MainActivity. Then again this could not get to, but changed getApplicationContext () successfully access to the location information ... What is the reason? I hope you can answer ... Thanks again!
Baidu Class Reference inside wrote: public LocationClient (Context) / / must be declared in the main thread Is a relationship with this, this is not the main thread?
This should be done only when an Activity, which this is the main thread, and when I do have multiple Activity when the Activity is another entrance, that is, at this time and then this, it is not in the main the thread ... do not know is not like that, so I do understand it first, if you have any good explanation, Could you tell me ... thank you! Reply:
only one Activity time, which this is the main thread, and when I do, when there are multiple Activity entrance Activity is another one, that is to say, at this time and then this, it is not in the main thread of the ... do not know if it is like this, so I do understand it first, if you have any good explanation, trouble You tell me ... thank you!
Official sample Baidu's what you saw, positioning inside with layers that example is this, rather than getapplicationcontext Reply: android: name = "com.baidu.location.f" android: enabled = "true" android: process = ": remote" android: exported = "false"> android: exported = "false" />
java files added option.setServiceName ("com.baidu.location.service"); Unable to start service to solve the problem. Bag with built-in service
No comments:
Post a Comment