|
|
@@ -12,6 +12,7 @@ import android.location.LocationManager;
|
|
|
import android.location.LocationProvider;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -198,7 +199,7 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
|
|
|
private HttpClient getHttpClient() {
|
|
|
if (mHttpClient == null) {
|
|
|
- mHttpClient = new HttpClient.Builder("http://api.map.baidu.com/place/v2/").isDebug(false)
|
|
|
+ mHttpClient = new HttpClient.Builder("https://maps.googleapis.com/maps/api/place/").isDebug(false)
|
|
|
.connectTimeout(5000)
|
|
|
.readTimeout(5000).build();
|
|
|
}
|
|
|
@@ -215,28 +216,26 @@ 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("search")
|
|
|
- .add("query", "公司")
|
|
|
+ .url("nearbysearch/json")
|
|
|
.add("location", latitude + "," + longitude)
|
|
|
.add("radius", radius)
|
|
|
.add("output", "json")
|
|
|
- .add("page_size", 1000)
|
|
|
- .add("page_num", 0)
|
|
|
- .add("ak", ct.getString(R.string.app_baidu_key))
|
|
|
- .add("mcode", ct.getString(R.string.app_baidu_code))
|
|
|
+ .add("key", ct.getString(R.string.app_google_key))
|
|
|
.build();
|
|
|
getHttpClient().Api().send(request, new ResultSubscriber<>(new Result2Listener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object s) {
|
|
|
- JSONObject object = JSON.parseObject(s.toString());
|
|
|
- if (object!=null&&object.containsKey("results")&&mOnSearchLocationListener!=null){
|
|
|
- try {
|
|
|
- handlerNeer(object.getJSONArray("results"),mOnSearchLocationListener);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ try {
|
|
|
+ JSONObject object = JSON.parseObject(s.toString());
|
|
|
+ if (object != null
|
|
|
+ && object.containsKey("status") && "OK".equals(object.getString("status").toUpperCase())
|
|
|
+ && object.containsKey("results") && mOnSearchLocationListener != null) {
|
|
|
+ handlerNeer(object.getJSONArray("results"), mOnSearchLocationListener);
|
|
|
}
|
|
|
+ MLOGGER.log(Level.INFO, s.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
}
|
|
|
- MLOGGER.log(Level.INFO, s.toString());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -254,21 +253,27 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
* @param keyWord
|
|
|
* @param mOnSearchLocationListener
|
|
|
*/
|
|
|
- public void loadByInput(Context ct, String city, String keyWord, OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
- HttpClient request = new HttpClient.Builder()
|
|
|
- .url("suggestion")
|
|
|
+ public void loadByInput(Context ct, String city, String keyWord,final OnSearchLocationListener mOnSearchLocationListener) {
|
|
|
+ HttpClient.Builder requestBuilder = new HttpClient.Builder()
|
|
|
+ .url("textsearch/json")
|
|
|
.add("query", keyWord)
|
|
|
- .add("region", city)
|
|
|
- .add("output", "json")
|
|
|
- .add("page_size", 1000)
|
|
|
- .add("page_num", 0)
|
|
|
- .add("ak", ct.getString(R.string.app_baidu_key))
|
|
|
- .add("mcode", ct.getString(R.string.app_baidu_code))
|
|
|
- .build();
|
|
|
+ .add("region", city)//城市
|
|
|
+ .add("key", ct.getString(R.string.app_google_key));
|
|
|
+ HttpClient request = requestBuilder.build();
|
|
|
getHttpClient().Api().send(request, new ResultSubscriber<>(new Result2Listener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object s) {
|
|
|
- MLOGGER.log(Level.INFO, s.toString());
|
|
|
+ try {
|
|
|
+ JSONObject object = JSON.parseObject(s.toString());
|
|
|
+ if (object != null
|
|
|
+ && object.containsKey("status") && "OK".equals(object.getString("status").toUpperCase())
|
|
|
+ && object.containsKey("results") && mOnSearchLocationListener != null) {
|
|
|
+ handlerNeer(object.getJSONArray("results"), mOnSearchLocationListener);
|
|
|
+ }
|
|
|
+ MLOGGER.log(Level.INFO, s .toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -287,29 +292,34 @@ public class NativeLocationManager implements BaseLocationManager {
|
|
|
object = array.getJSONObject(i);
|
|
|
mUASLocation = new UASLocation(UASLocation.TYPE_NATIVE);
|
|
|
String name = object.getString("name");
|
|
|
- String address = object.getString("address");
|
|
|
- String province = object.getString("province");
|
|
|
- String city = object.getString("city");
|
|
|
- String area = object.getString("area");
|
|
|
-
|
|
|
+ String address = null;
|
|
|
+ if (object.containsKey("vicinity")) {
|
|
|
+ address = object.getString("vicinity");
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(address) && object.containsKey("formatted_address")) {
|
|
|
+ address = object.getString("formatted_address");
|
|
|
+ }
|
|
|
+// String province = object.getString("province");
|
|
|
+ String city = object.getString("city");//TODO 城市
|
|
|
+// String area = object.getString("area");
|
|
|
mUASLocation.setName(name);
|
|
|
mUASLocation.setAddress(address);
|
|
|
- mUASLocation.setProvince(province);
|
|
|
mUASLocation.setCityName(city);
|
|
|
- mUASLocation.setDistrict(area);
|
|
|
- mUASLocation.setDistrict(area);
|
|
|
- JSONObject location = object.getJSONObject("location");
|
|
|
- if (location != null) {
|
|
|
- float lat = location.getFloat("lat");
|
|
|
- float lng = location.getFloat("lng");
|
|
|
- if (lat > 0 && lng > 0) {
|
|
|
- mUASLocation.setLatitude(lat);
|
|
|
- mUASLocation.setLongitude(lng);
|
|
|
+ JSONObject geometry = object.getJSONObject("geometry");
|
|
|
+ if (geometry != null) {
|
|
|
+ JSONObject location = geometry.getJSONObject("location");
|
|
|
+ if (location != null) {
|
|
|
+ float lat = location.getFloat("lat");
|
|
|
+ float lng = location.getFloat("lng");
|
|
|
+ if (lat > 0 && lng > 0) {
|
|
|
+ mUASLocation.setLatitude(lat);
|
|
|
+ mUASLocation.setLongitude(lng);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
mUASLocations.add(mUASLocation);
|
|
|
}
|
|
|
- mOnSearchLocationListener.onCallBack(true,mUASLocations);
|
|
|
+ mOnSearchLocationListener.onCallBack(true, mUASLocations);
|
|
|
}
|
|
|
|
|
|
|