Thursday, February 13, 2014

Baidu Maps API MKSearch in the first run, MKSearchListener no return value


First on the code

public class BusinessActivity extends MapActivity implements OnClickListener {

private SharedPreferences gpsinfo;
private String latitude, longitude, addrStr;
private BMapManager mapManager;
private MKSearch mMKSearch;
private MapView mapView;
private GeoPoint gpt;
private View btnFood, btnSnack, btnCoffee, btnFilm, btnKtv, btnMore;
private ArrayList poiList = new ArrayList ();

public void onCreate (Bundle bundle) {
super.onCreate (bundle);
requestWindowFeature (Window.FEATURE_NO_TITLE);
setContentView (R.layout.all_companies_layout);
findById ();
setOnClickListener ();
initView ();

/ / Initialize MKSearch
mMKSearch = new MKSearch ();
mMKSearch.init (mapManager, new MySearchListener ());

gpsinfo = getSharedPreferences ("GPS_INFOS", 0);
latitude = gpsinfo.getString ("LATITUDE", "");
longitude = gpsinfo.getString ("LONGITUDE", "");
addrStr = gpsinfo.getString ("ADDRSTR", "");

gpt = new GeoPoint ((int) (Double.valueOf (latitude) * 1e6), (int) (Double.valueOf (longitude) * 1e6));

if (StringUtils.isEmpty (addrStr)) {
/ / Query the latitude and longitude values ​​corresponding to the address location information
mMKSearch.reverseGeocode (gpt);
}
}

public void findById () {
btnFood = findViewById (R.id.food_u);
}

public void setOnClickListener () {
btnFood.setOnClickListener (this);
}

public void initView () {
/ / Initialize MapActivity
mapManager = new BMapManager (getApplication ());
The first parameter / / init methods need to fill an application API Key
mapManager.init ("285B415EBAB2A92293E85502150ADA7F03C777C4", null);
super.initMapActivity (mapManager);
mapView = (MapView) findViewById (R.id.map_View);
/ / Set the map mode to traffic maps
mapView.setTraffic (true);
/ / Set to enable the built-in zoom controls
mapView.setBuiltInZoomControls (true);
/ / Set the zoom animation process also display overlay, the default is not drawn
mapView.setDrawOverlayWhenZooming (true);
}


public void onClick (View v) {
Intent intent = new Intent ();
switch (v.getId ()) {
case R.id.food_u:
mMKSearch.poiSearchNearBy (ContentUtils.SELECT_FOOD, gpt, 500);
intent.putExtra ("SELECT_CATEGORY", ContentUtils.SELECT_FOOD);
intent.putStringArrayListExtra ("STORE_INFO_LIST", storeList);
intent.setClass (BusinessActivity.this, BusinessResultActivity.class);
break;
default:
break;

}


startActivity (intent);
}

@ Override
protected boolean isRouteDisplayed () {
return false;
}

@ Override
protected void onDestroy () {
if (mapManager! = null) {
Front / / program exits need to call this method
mapManager.destroy ();
mapManager = null;
}
super.onDestroy ();
}

@ Override
protected void onPause () {
if (mapManager! = null) {
/ / End Baidu Maps API
mapManager.stop ();
}
super.onPause ();
}

@ Override
protected void onResume () {
if (mapManager! = null) {
/ / Open Baidu Maps API
mapManager.start ();
}
super.onResume ();
}

/ **
* Internal MKSearchListener class implements an interface, used to implement asynchronous search service
*
* /
public class MySearchListener implements MKSearchListener {

public void onGetAddrResult (MKAddrInfo result, int arg1) {
if (result == null) {
return;
}
/ / Position corresponding to the latitude and longitude
addrStr = result.strAddr;
}

public void onGetPoiDetailSearchResult (int arg0, int arg1) {}

public void onGetPoiResult (MKPoiResult result, int arg1, int arg2) {
poiList.clear ();
if (result == null) {
return;
}
poiList = result.getAllPoi ();
Collections.sort (poiList, new Comparator () {
public int compare (MKPoiInfo lhs, MKPoiInfo rhs) {
! assert (lhs.uid) = null;
! assert (rhs.uid) = null;
return lhs.uid.compareTo (rhs.uid);
}
});
}

public void onGetBusDetailResult (MKBusLineResult arg0, int arg1) {}

public void onGetDrivingRouteResult (MKDrivingRouteResult arg0, int arg1) {}

public void onGetRGCShareUrlResult (String arg0, int arg1) {}

public void onGetSuggestionResult (MKSuggestionResult arg0, int arg1) {}

public void onGetTransitRouteResult (MKTransitRouteResult arg0, int arg1) {}

public void onGetWalkingRouteResult (MKWalkingRouteResult arg0, int arg1) {}
}
}


Why jump to the first screen poiList is empty, while the second will use the data,
That is why, newcomers seek advice .....



<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:

Reply:
Great God csdn say much, how no one answered it
Reply:
Themselves, and get
Reply:
LZ what is the reason ah
Reply:
The landlord recently not come yet, ask how to solve ah, I tried to get the data in another thread, but the effect is not good, can share experiences, thank you.

No comments:

Post a Comment