aeb0af84 by chiangbt

更新了高德检索POI

1 parent 62e1fc5c
......@@ -17,10 +17,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".BootActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
......@@ -29,7 +26,10 @@
android:theme="@style/AppTheme.NoActionBar"> <!-- 禁止屏幕旋转 -->
</activity>
<activity android:name=".GoogleMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaiduMapActivity">
......
......@@ -5,31 +5,53 @@ import android.location.LocationListener;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.JSONObjectRequestListener;
import com.arlib.floatingsearchview.FloatingSearchView;
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion;
import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapView;
import com.esri.android.runtime.ArcGISRuntime;
import com.esri.core.geometry.Point;
import com.esri.core.map.Graphic;
import com.esri.core.symbol.PictureMarkerSymbol;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes;
import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.layers.tencent.TencentMapLayerTypes;
import com.pashanhoo.landsurvey.layers.tencent.TencentMapsTiledServiceLayer;
import com.pashanhoo.landsurvey.search.POISuggestion;
import com.pashanhoo.landsurvey.utils.AppInfo;
import com.pashanhoo.landsurvey.utils.GISHelper;
import com.pashanhoo.landsurvey.utils.JZLocationConverter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class GoogleMapActivity extends AppCompatActivity {
private MapView mapView;
// 地图中的GraphicsLayer对象
private GraphicsLayer graphicsLayer;
// GPS定位器对象
private LocationDisplayManager locationDisplayManager;
// 浮动查询条
private FloatingSearchView floatingSearchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
floatingSearchView = (FloatingSearchView) findViewById(R.id.floating_search_view);
AppInfo.Settings();
......@@ -49,14 +71,14 @@ public class GoogleMapActivity extends AppCompatActivity {
//---------------------------------------------------------------------------------------------------------------------
// 高德矢量图层(含路网,含注记)
GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
final GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR);
// 高德影像图层(不含路网,不含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE);
// 高德路网图层(含路网,含注记)
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD);
// 高德实时交通图层
// GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC);
// mapView.addLayer(gaodeMapsTiledServiceLayer);
mapView.addLayer(gaodeMapsTiledServiceLayer);
//---------------------------------------------------------------------------------------------------------------------
TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR);
......@@ -66,6 +88,9 @@ public class GoogleMapActivity extends AppCompatActivity {
// GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile);
// mapView.addLayer(geoQMapsTiledServiceLayer);
// 添加GraphicsLayer
graphicsLayer = new GraphicsLayer();
mapView.addLayer(graphicsLayer);
mapView.setMaxResolution(156543.03392800014);
mapView.setMinResolution(0.29858214164761665);
......@@ -120,6 +145,58 @@ public class GoogleMapActivity extends AppCompatActivity {
}
}
});
// 处理浮动查询条
floatingSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {
@Override
public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
graphicsLayer.removeAll();
POISuggestion colorSuggestion = (POISuggestion) searchSuggestion;
Point poipt = new Point(colorSuggestion.getLng(), colorSuggestion.getLat());
mapView.zoomToResolution(GISHelper.lonLat2Mercator(poipt), gaodeMapsTiledServiceLayer.getRes()[19]);
graphicsLayer.addGraphic(new Graphic(GISHelper.lonLat2Mercator(poipt),
new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16)));
}
@Override
public void onSearchAction(String currentQuery) {
if (currentQuery.length() >= 3) {
floatingSearchView.clearSuggestions();
// 查询天地图API
String str = "http://restapi.amap.com/v3/place/text?keywords="+ currentQuery
+"&output=json&offset=15&page=1&key=f1713c28f00da34d6ee23dccb7f74b81&extensions=all";
AndroidNetworking.get(str)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
//解析响应结果
JSONArray Jarray = null;
try {
Jarray = response.getJSONArray("pois");
ArrayList<POISuggestion> poiSuggestions = new ArrayList<POISuggestion>();
for (int i = 0; i < Jarray.length(); i++) {
JSONObject Jasonobject = Jarray.getJSONObject(i);
poiSuggestions.add(new POISuggestion(Jasonobject.getString("name"),
Jasonobject.getString("address"),
Jasonobject.getString("location").replace(",", " ")));
}
floatingSearchView.swapSuggestions(poiSuggestions);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ANError anError) {
Log.i("error", anError.getMessage());
}
});
}
}
});
}
@Override
......
......@@ -31,6 +31,7 @@ import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLocalTiledMapServiceLaye
import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuTiledMapServiceLayer;
import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLayerTypes;
import com.pashanhoo.landsurvey.search.POISuggestion;
import com.pashanhoo.landsurvey.search.TiandituSearch;
import com.pashanhoo.landsurvey.utils.AppInfo;
import org.json.JSONArray;
......@@ -248,7 +249,9 @@ public class MainActivity extends AppCompatActivity {
if (currentQuery.length() > 3) {
floatingSearchView.clearSuggestions();
// 查询天地图API
String str = "{\"keyWord\":\"" + currentQuery + "\",\"level\":\"11\",\"mapBound\":\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\",\"start\":\"0\",\"queryTerminal\":\"1000\"}";
String str = "{\"keyWord\":\"" + currentQuery + "\",\"level\":\"11\",\"mapBound\":" +
"\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"," +
"\"start\":\"0\",\"queryTerminal\":\"1000\"}";
AndroidNetworking.post("http://map.tianditu.com/query.shtml")
.addBodyParameter("type", "query")
.addBodyParameter("postStr", str)
......
......@@ -11,9 +11,9 @@ import org.json.JSONObject;
import java.util.ArrayList;
public class TiandituSearch {
private static ArrayList<POISuggestion> poiSuggestionArrayList = new ArrayList<POISuggestion>();
public static ArrayList<POISuggestion> getPoi(String name){
final ArrayList<POISuggestion> poiSuggestionArrayList = new ArrayList<POISuggestion>();
String str = "{\"keyWord\":\"" + name + "\",\"level\":\"11\",\"mapBound\":" +
"\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"" +
......@@ -43,7 +43,7 @@ public class TiandituSearch {
@Override
public void onError(ANError anError) {
poiSuggestionArrayList = null;
// poiSuggestionArrayList = null;
}
});
return poiSuggestionArrayList;
......
......@@ -11,11 +11,25 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"></com.esri.android.map.MapView>
<com.arlib.floatingsearchview.FloatingSearchView
android:id="@+id/floating_search_view"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:visibility="visible"
app:floatingSearch_searchHint="地名地址检索..."
app:floatingSearch_suggestionsListAnimDuration="250"
app:floatingSearch_showSearchKey="true"
app:floatingSearch_leftActionMode="showHome"
app:floatingSearch_close_search_on_keyboard_dismiss="true"/>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="16dp"
android:layout_marginTop="76dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_gravity="top|start">
......