更新了高德检索POI
Showing
5 changed files
with
105 additions
and
11 deletions
... | @@ -17,10 +17,7 @@ | ... | @@ -17,10 +17,7 @@ |
17 | android:supportsRtl="true" | 17 | android:supportsRtl="true" |
18 | android:theme="@style/AppTheme"> | 18 | android:theme="@style/AppTheme"> |
19 | <activity android:name=".BootActivity" > | 19 | <activity android:name=".BootActivity" > |
20 | <intent-filter> | 20 | |
21 | <action android:name="android.intent.action.MAIN" /> | ||
22 | <category android:name="android.intent.category.LAUNCHER" /> | ||
23 | </intent-filter> | ||
24 | </activity> | 21 | </activity> |
25 | <activity | 22 | <activity |
26 | android:name=".MainActivity" | 23 | android:name=".MainActivity" |
... | @@ -29,7 +26,10 @@ | ... | @@ -29,7 +26,10 @@ |
29 | android:theme="@style/AppTheme.NoActionBar"> <!-- 禁止屏幕旋转 --> | 26 | android:theme="@style/AppTheme.NoActionBar"> <!-- 禁止屏幕旋转 --> |
30 | </activity> | 27 | </activity> |
31 | <activity android:name=".GoogleMapActivity"> | 28 | <activity android:name=".GoogleMapActivity"> |
32 | 29 | <intent-filter> | |
30 | <action android:name="android.intent.action.MAIN" /> | ||
31 | <category android:name="android.intent.category.LAUNCHER" /> | ||
32 | </intent-filter> | ||
33 | </activity> | 33 | </activity> |
34 | <activity android:name=".BaiduMapActivity"> | 34 | <activity android:name=".BaiduMapActivity"> |
35 | 35 | ... | ... |
... | @@ -5,31 +5,53 @@ import android.location.LocationListener; | ... | @@ -5,31 +5,53 @@ import android.location.LocationListener; |
5 | import android.support.design.widget.FloatingActionButton; | 5 | import android.support.design.widget.FloatingActionButton; |
6 | import android.support.v7.app.AppCompatActivity; | 6 | import android.support.v7.app.AppCompatActivity; |
7 | import android.os.Bundle; | 7 | import android.os.Bundle; |
8 | import android.util.Log; | ||
8 | import android.view.View; | 9 | import android.view.View; |
9 | import android.widget.Toast; | 10 | import android.widget.Toast; |
10 | 11 | ||
12 | import com.androidnetworking.AndroidNetworking; | ||
13 | import com.androidnetworking.error.ANError; | ||
14 | import com.androidnetworking.interfaces.JSONObjectRequestListener; | ||
15 | import com.arlib.floatingsearchview.FloatingSearchView; | ||
16 | import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion; | ||
17 | import com.esri.android.map.GraphicsLayer; | ||
11 | import com.esri.android.map.LocationDisplayManager; | 18 | import com.esri.android.map.LocationDisplayManager; |
12 | import com.esri.android.map.MapView; | 19 | import com.esri.android.map.MapView; |
13 | import com.esri.android.runtime.ArcGISRuntime; | 20 | import com.esri.android.runtime.ArcGISRuntime; |
14 | import com.esri.core.geometry.Point; | 21 | import com.esri.core.geometry.Point; |
22 | import com.esri.core.map.Graphic; | ||
23 | import com.esri.core.symbol.PictureMarkerSymbol; | ||
15 | import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes; | 24 | import com.pashanhoo.landsurvey.layers.gaode.GaodeMapLayerTypes; |
16 | import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer; | 25 | import com.pashanhoo.landsurvey.layers.gaode.GaodeMapsTiledServiceLayer; |
17 | import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer; | 26 | import com.pashanhoo.landsurvey.layers.google.GoogleMapsTiledServiceLayer; |
18 | import com.pashanhoo.landsurvey.layers.tencent.TencentMapLayerTypes; | 27 | import com.pashanhoo.landsurvey.layers.tencent.TencentMapLayerTypes; |
19 | import com.pashanhoo.landsurvey.layers.tencent.TencentMapsTiledServiceLayer; | 28 | import com.pashanhoo.landsurvey.layers.tencent.TencentMapsTiledServiceLayer; |
29 | import com.pashanhoo.landsurvey.search.POISuggestion; | ||
20 | import com.pashanhoo.landsurvey.utils.AppInfo; | 30 | import com.pashanhoo.landsurvey.utils.AppInfo; |
21 | import com.pashanhoo.landsurvey.utils.GISHelper; | 31 | import com.pashanhoo.landsurvey.utils.GISHelper; |
22 | import com.pashanhoo.landsurvey.utils.JZLocationConverter; | 32 | import com.pashanhoo.landsurvey.utils.JZLocationConverter; |
23 | 33 | ||
34 | import org.json.JSONArray; | ||
35 | import org.json.JSONException; | ||
36 | import org.json.JSONObject; | ||
37 | |||
38 | import java.util.ArrayList; | ||
39 | |||
24 | public class GoogleMapActivity extends AppCompatActivity { | 40 | public class GoogleMapActivity extends AppCompatActivity { |
25 | 41 | ||
26 | private MapView mapView; | 42 | private MapView mapView; |
43 | // 地图中的GraphicsLayer对象 | ||
44 | private GraphicsLayer graphicsLayer; | ||
27 | // GPS定位器对象 | 45 | // GPS定位器对象 |
28 | private LocationDisplayManager locationDisplayManager; | 46 | private LocationDisplayManager locationDisplayManager; |
47 | // 浮动查询条 | ||
48 | private FloatingSearchView floatingSearchView; | ||
49 | |||
29 | @Override | 50 | @Override |
30 | protected void onCreate(Bundle savedInstanceState) { | 51 | protected void onCreate(Bundle savedInstanceState) { |
31 | super.onCreate(savedInstanceState); | 52 | super.onCreate(savedInstanceState); |
32 | setContentView(R.layout.activity_google_map); | 53 | setContentView(R.layout.activity_google_map); |
54 | floatingSearchView = (FloatingSearchView) findViewById(R.id.floating_search_view); | ||
33 | 55 | ||
34 | AppInfo.Settings(); | 56 | AppInfo.Settings(); |
35 | 57 | ||
... | @@ -49,14 +71,14 @@ public class GoogleMapActivity extends AppCompatActivity { | ... | @@ -49,14 +71,14 @@ public class GoogleMapActivity extends AppCompatActivity { |
49 | 71 | ||
50 | //--------------------------------------------------------------------------------------------------------------------- | 72 | //--------------------------------------------------------------------------------------------------------------------- |
51 | // 高德矢量图层(含路网,含注记) | 73 | // 高德矢量图层(含路网,含注记) |
52 | GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR); | 74 | final GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_VECTOR); |
53 | // 高德影像图层(不含路网,不含注记) | 75 | // 高德影像图层(不含路网,不含注记) |
54 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE); | 76 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_IMAGE); |
55 | // 高德路网图层(含路网,含注记) | 77 | // 高德路网图层(含路网,含注记) |
56 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD); | 78 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_ROAD); |
57 | // 高德实时交通图层 | 79 | // 高德实时交通图层 |
58 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC); | 80 | // GaodeMapsTiledServiceLayer gaodeMapsTiledServiceLayer = new GaodeMapsTiledServiceLayer(GaodeMapLayerTypes.AMAP_TRAFFIC); |
59 | // mapView.addLayer(gaodeMapsTiledServiceLayer); | 81 | mapView.addLayer(gaodeMapsTiledServiceLayer); |
60 | //--------------------------------------------------------------------------------------------------------------------- | 82 | //--------------------------------------------------------------------------------------------------------------------- |
61 | 83 | ||
62 | TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR); | 84 | TencentMapsTiledServiceLayer tencentMapsTiledServiceLayer = new TencentMapsTiledServiceLayer(TencentMapLayerTypes.TENCENT_MAP_VECTOR); |
... | @@ -66,6 +88,9 @@ public class GoogleMapActivity extends AppCompatActivity { | ... | @@ -66,6 +88,9 @@ public class GoogleMapActivity extends AppCompatActivity { |
66 | // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile); | 88 | // GeoQMapsTiledServiceLayer geoQMapsTiledServiceLayer = new GeoQMapsTiledServiceLayer(GeoQMapLayerTypes.ChinaOnlineCommunity_Mobile); |
67 | // mapView.addLayer(geoQMapsTiledServiceLayer); | 89 | // mapView.addLayer(geoQMapsTiledServiceLayer); |
68 | 90 | ||
91 | // 添加GraphicsLayer | ||
92 | graphicsLayer = new GraphicsLayer(); | ||
93 | mapView.addLayer(graphicsLayer); | ||
69 | 94 | ||
70 | mapView.setMaxResolution(156543.03392800014); | 95 | mapView.setMaxResolution(156543.03392800014); |
71 | mapView.setMinResolution(0.29858214164761665); | 96 | mapView.setMinResolution(0.29858214164761665); |
... | @@ -120,6 +145,58 @@ public class GoogleMapActivity extends AppCompatActivity { | ... | @@ -120,6 +145,58 @@ public class GoogleMapActivity extends AppCompatActivity { |
120 | } | 145 | } |
121 | } | 146 | } |
122 | }); | 147 | }); |
148 | |||
149 | // 处理浮动查询条 | ||
150 | floatingSearchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { | ||
151 | @Override | ||
152 | public void onSuggestionClicked(SearchSuggestion searchSuggestion) { | ||
153 | graphicsLayer.removeAll(); | ||
154 | |||
155 | POISuggestion colorSuggestion = (POISuggestion) searchSuggestion; | ||
156 | Point poipt = new Point(colorSuggestion.getLng(), colorSuggestion.getLat()); | ||
157 | mapView.zoomToResolution(GISHelper.lonLat2Mercator(poipt), gaodeMapsTiledServiceLayer.getRes()[19]); | ||
158 | |||
159 | graphicsLayer.addGraphic(new Graphic(GISHelper.lonLat2Mercator(poipt), | ||
160 | new PictureMarkerSymbol(getResources().getDrawable(R.mipmap.locator)).setOffsetY(16))); | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public void onSearchAction(String currentQuery) { | ||
165 | if (currentQuery.length() >= 3) { | ||
166 | floatingSearchView.clearSuggestions(); | ||
167 | // 查询天地图API | ||
168 | String str = "http://restapi.amap.com/v3/place/text?keywords="+ currentQuery | ||
169 | +"&output=json&offset=15&page=1&key=f1713c28f00da34d6ee23dccb7f74b81&extensions=all"; | ||
170 | AndroidNetworking.get(str) | ||
171 | .build() | ||
172 | .getAsJSONObject(new JSONObjectRequestListener() { | ||
173 | @Override | ||
174 | public void onResponse(JSONObject response) { | ||
175 | //解析响应结果 | ||
176 | JSONArray Jarray = null; | ||
177 | try { | ||
178 | Jarray = response.getJSONArray("pois"); | ||
179 | ArrayList<POISuggestion> poiSuggestions = new ArrayList<POISuggestion>(); | ||
180 | for (int i = 0; i < Jarray.length(); i++) { | ||
181 | JSONObject Jasonobject = Jarray.getJSONObject(i); | ||
182 | poiSuggestions.add(new POISuggestion(Jasonobject.getString("name"), | ||
183 | Jasonobject.getString("address"), | ||
184 | Jasonobject.getString("location").replace(",", " "))); | ||
185 | } | ||
186 | floatingSearchView.swapSuggestions(poiSuggestions); | ||
187 | } catch (JSONException e) { | ||
188 | e.printStackTrace(); | ||
189 | } | ||
190 | } | ||
191 | |||
192 | @Override | ||
193 | public void onError(ANError anError) { | ||
194 | Log.i("error", anError.getMessage()); | ||
195 | } | ||
196 | }); | ||
197 | } | ||
198 | } | ||
199 | }); | ||
123 | } | 200 | } |
124 | 201 | ||
125 | @Override | 202 | @Override | ... | ... |
... | @@ -31,6 +31,7 @@ import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLocalTiledMapServiceLaye | ... | @@ -31,6 +31,7 @@ import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLocalTiledMapServiceLaye |
31 | import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuTiledMapServiceLayer; | 31 | import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuTiledMapServiceLayer; |
32 | import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLayerTypes; | 32 | import com.pashanhoo.landsurvey.layers.tianditu.TianDiTuLayerTypes; |
33 | import com.pashanhoo.landsurvey.search.POISuggestion; | 33 | import com.pashanhoo.landsurvey.search.POISuggestion; |
34 | import com.pashanhoo.landsurvey.search.TiandituSearch; | ||
34 | import com.pashanhoo.landsurvey.utils.AppInfo; | 35 | import com.pashanhoo.landsurvey.utils.AppInfo; |
35 | 36 | ||
36 | import org.json.JSONArray; | 37 | import org.json.JSONArray; |
... | @@ -248,7 +249,9 @@ public class MainActivity extends AppCompatActivity { | ... | @@ -248,7 +249,9 @@ public class MainActivity extends AppCompatActivity { |
248 | if (currentQuery.length() > 3) { | 249 | if (currentQuery.length() > 3) { |
249 | floatingSearchView.clearSuggestions(); | 250 | floatingSearchView.clearSuggestions(); |
250 | // 查询天地图API | 251 | // 查询天地图API |
251 | String str = "{\"keyWord\":\"" + currentQuery + "\",\"level\":\"11\",\"mapBound\":\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\",\"start\":\"0\",\"queryTerminal\":\"1000\"}"; | 252 | String str = "{\"keyWord\":\"" + currentQuery + "\",\"level\":\"11\",\"mapBound\":" + |
253 | "\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"," + | ||
254 | "\"start\":\"0\",\"queryTerminal\":\"1000\"}"; | ||
252 | AndroidNetworking.post("http://map.tianditu.com/query.shtml") | 255 | AndroidNetworking.post("http://map.tianditu.com/query.shtml") |
253 | .addBodyParameter("type", "query") | 256 | .addBodyParameter("type", "query") |
254 | .addBodyParameter("postStr", str) | 257 | .addBodyParameter("postStr", str) | ... | ... |
... | @@ -11,9 +11,9 @@ import org.json.JSONObject; | ... | @@ -11,9 +11,9 @@ import org.json.JSONObject; |
11 | import java.util.ArrayList; | 11 | import java.util.ArrayList; |
12 | 12 | ||
13 | public class TiandituSearch { | 13 | public class TiandituSearch { |
14 | private static ArrayList<POISuggestion> poiSuggestionArrayList = new ArrayList<POISuggestion>(); | ||
15 | 14 | ||
16 | public static ArrayList<POISuggestion> getPoi(String name){ | 15 | public static ArrayList<POISuggestion> getPoi(String name){ |
16 | final ArrayList<POISuggestion> poiSuggestionArrayList = new ArrayList<POISuggestion>(); | ||
17 | 17 | ||
18 | String str = "{\"keyWord\":\"" + name + "\",\"level\":\"11\",\"mapBound\":" + | 18 | String str = "{\"keyWord\":\"" + name + "\",\"level\":\"11\",\"mapBound\":" + |
19 | "\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"" + | 19 | "\"76.24832,30.1129,156.40458,49.97618\",\"queryType\":\"1\",\"count\":\"10\"" + |
... | @@ -43,7 +43,7 @@ public class TiandituSearch { | ... | @@ -43,7 +43,7 @@ public class TiandituSearch { |
43 | 43 | ||
44 | @Override | 44 | @Override |
45 | public void onError(ANError anError) { | 45 | public void onError(ANError anError) { |
46 | poiSuggestionArrayList = null; | 46 | // poiSuggestionArrayList = null; |
47 | } | 47 | } |
48 | }); | 48 | }); |
49 | return poiSuggestionArrayList; | 49 | return poiSuggestionArrayList; | ... | ... |
... | @@ -11,11 +11,25 @@ | ... | @@ -11,11 +11,25 @@ |
11 | android:layout_width="fill_parent" | 11 | android:layout_width="fill_parent" |
12 | android:layout_height="fill_parent"></com.esri.android.map.MapView> | 12 | android:layout_height="fill_parent"></com.esri.android.map.MapView> |
13 | 13 | ||
14 | <com.arlib.floatingsearchview.FloatingSearchView | ||
15 | android:id="@+id/floating_search_view" | ||
16 | android:layout_width="300dp" | ||
17 | android:layout_height="match_parent" | ||
18 | android:layout_marginTop="10dp" | ||
19 | android:layout_marginLeft="16dp" | ||
20 | android:layout_marginBottom="16dp" | ||
21 | android:visibility="visible" | ||
22 | app:floatingSearch_searchHint="地名地址检索..." | ||
23 | app:floatingSearch_suggestionsListAnimDuration="250" | ||
24 | app:floatingSearch_showSearchKey="true" | ||
25 | app:floatingSearch_leftActionMode="showHome" | ||
26 | app:floatingSearch_close_search_on_keyboard_dismiss="true"/> | ||
27 | |||
14 | <android.support.v7.widget.LinearLayoutCompat | 28 | <android.support.v7.widget.LinearLayoutCompat |
15 | android:layout_width="match_parent" | 29 | android:layout_width="match_parent" |
16 | android:layout_height="match_parent" | 30 | android:layout_height="match_parent" |
17 | android:orientation="vertical" | 31 | android:orientation="vertical" |
18 | android:layout_marginTop="16dp" | 32 | android:layout_marginTop="76dp" |
19 | android:layout_marginLeft="16dp" | 33 | android:layout_marginLeft="16dp" |
20 | android:layout_marginBottom="16dp" | 34 | android:layout_marginBottom="16dp" |
21 | android:layout_gravity="top|start"> | 35 | android:layout_gravity="top|start"> | ... | ... |
-
Please register or sign in to post a comment