|
|
@@ -11,6 +11,8 @@ import android.location.LocationListener;
|
|
|
import android.location.LocationManager;
|
|
|
import android.location.LocationProvider;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Looper;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
@@ -20,6 +22,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baidu.mapapi.model.LatLng;
|
|
|
import com.me.network.app.http.HttpClient;
|
|
|
+import com.me.network.app.http.Method;
|
|
|
import com.me.network.app.http.rx.Result2Listener;
|
|
|
import com.me.network.app.http.rx.ResultSubscriber;
|
|
|
import com.uas.applocation.Interface.OnLocationListener;
|
|
|
@@ -206,6 +209,28 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
return mHttpClient;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 由于google收费,必须限制每天使用量
|
|
|
+ */
|
|
|
+ private String lastKey;
|
|
|
+ private boolean isWhating, isResulting = false;
|
|
|
+ private Handler mWhatHandler = new Handler(Looper.getMainLooper());
|
|
|
+
|
|
|
+ private void startWhat(final Context ct, final OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
+ if (!isWhating) {
|
|
|
+ isWhating = true;
|
|
|
+ mWhatHandler.postAtTime(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ isWhating = false;
|
|
|
+ loadByInput(ct, null, lastKey, mOnSearchLocationListener);
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前位置附近位置
|
|
|
*
|
|
|
@@ -217,9 +242,11 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
public void loadNativeByNeer(final Context ct, double latitude, double longitude, float radius, final OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
HttpClient request = new HttpClient.Builder()
|
|
|
.url("nearbysearch/json")
|
|
|
+ .isDebug(true)
|
|
|
.add("location", latitude + "," + longitude)
|
|
|
.add("radius", radius)
|
|
|
.add("output", "json")
|
|
|
+ .method(Method.GET)
|
|
|
.add("key", ct.getString(R.string.app_google_key))
|
|
|
.build();
|
|
|
getHttpClient().Api().send(request, new ResultSubscriber<>(new Result2Listener<Object>() {
|
|
|
@@ -253,11 +280,19 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
* @param keyWord
|
|
|
* @param mOnSearchLocationListener
|
|
|
*/
|
|
|
- public void loadByInput(Context ct, String city, String keyWord,final OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
+ public void loadByInput(Context ct, String city, String keyWord, final OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
+ this.lastKey = keyWord;
|
|
|
+ if (isWhating || isResulting) {
|
|
|
+ startWhat(ct,mOnSearchLocationListener);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ isResulting = true;
|
|
|
HttpClient.Builder requestBuilder = new HttpClient.Builder()
|
|
|
+ .isDebug(true)
|
|
|
.url("textsearch/json")
|
|
|
.add("query", keyWord)
|
|
|
- .add("region", city)//城市
|
|
|
+// .add("region", city)//城市
|
|
|
+ .method(Method.GET)
|
|
|
.add("key", ct.getString(R.string.app_google_key));
|
|
|
HttpClient request = requestBuilder.build();
|
|
|
getHttpClient().Api().send(request, new ResultSubscriber<>(new Result2Listener<Object>() {
|
|
|
@@ -270,9 +305,11 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
&& object.containsKey("results") && mOnSearchLocationListener != null) {
|
|
|
handlerNeer(object.getJSONArray("results"), mOnSearchLocationListener);
|
|
|
}
|
|
|
- MLOGGER.log(Level.INFO, s .toString());
|
|
|
+ MLOGGER.log(Level.INFO, s.toString());
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
+ } finally {
|
|
|
+ isResulting = false;
|
|
|
}
|
|
|
}
|
|
|
|