本地查询可以查询指定区域内诸如宾馆,邮局等用户感兴趣的地方。其使用方法和地址查询非常类似。
下面示例查询32.0616667, 118.7777778为中心点一定区域内宾馆的信息。
package com.pstreets.gisengine.demo; import com.mapdigit.gis.MapPoint; import com.mapdigit.gis.geometry.GeoLatLng; import com.mapdigit.gis.service.DigitalMapService; import com.mapdigit.gis.service.IGeocodingListener; import com.pstreets.gisengine.R; import com.pstreets.gisengine.SharedMapInstance; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; public class MapLocalSearch extends Activity implements IGeocodingListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public void onStart() { super.onStart(); GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778); SharedMapInstance.map.setCenter(center, 15, com.mapdigit.gis.raster.MapType.MICROSOFTCHINA); DigitalMapService.getSearchOptions().LanguageID = "zh-cn"; SharedMapInstance.map.setGeocodingListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.maplocalsearch_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.findaddress: String name = "宾馆"; GeoLatLng screenCenter = SharedMapInstance.map.getScreenCenter(); SharedMapInstance.map.getLocations(name, 0, screenCenter, SharedMapInstance.map.getScreenBounds(screenCenter)); return true; default: return super.onOptionsItemSelected(item); } } @Override public void done(String query, MapPoint[] result) { if (result != null) { SharedMapInstance.map.panTo(result[0].getPoint()); for (int i = 0; i < result.length; i++) { System.out.println(result[i].objectNote); } } } @Override public void readProgress(int bytes, int total) { } }
本地查询方法
public void getLocations(String address,int start,GeoLatLng center,GeoBounds bound, IGeocodingListener listener);
指定中心点和查询区域。本地查询可以多次返回结果,start为查询结果起始顺序,每次返回结果在SearchOptions 中定义,缺省每次返回4个。
上述结果返回内容为,具体结果可能不同。
“晶丽酒店025-83310818 025-83310818212223 025-86636636 ”
“城市名人酒店025-83123333 025-83123888 ”
“南京玄武饭店 025-83358888 ”
“Sofitel Galaxy Nanjing – 南京索菲特银河大酒店025-83718888 “