最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android百度地圖poi范圍搜索

 更新時(shí)間:2016年02月05日 10:47:42   投稿:mrr  
這篇文章主要介紹了Android百度地圖poi范圍搜索的相關(guān)資料,需要的朋友可以參考下

我想大家可能都有過(guò)這樣的經(jīng)歷:兜里揣著一張銀行卡,在街上到處找自動(dòng)取款機(jī)(ATM)。在這個(gè)場(chǎng)景中,ATM就是的興趣點(diǎn),我們想做的事情就是找到離自己較近的一些ATM然后取款,此時(shí)我們并不關(guān)心附近有哪些超市、酒吧,因?yàn)檫@些地方?jīng)]辦法取錢!

說(shuō)了這么多,一方面是加深大家對(duì)POI這個(gè)詞的認(rèn)識(shí),另一方面也是為了讓大家明白我們接下來(lái)要做的事情。理論性的東西就不再多講了,直接來(lái)看例子。

先給大家展示下效果圖:

詳細(xì)界面:

該示例主要介紹關(guān)鍵詞查詢、suggestion查詢和查看餐飲類Place詳情頁(yè)功能,尤其搜索某個(gè)地方的餐廳、理發(fā)店等等比較有實(shí)際意義,百度Demo代碼如下:

Activity:

package com.home;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.Toast;
import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.MKAddrInfo;
import com.baidu.mapapi.search.MKBusLineResult;
import com.baidu.mapapi.search.MKDrivingRouteResult;
import com.baidu.mapapi.search.MKPoiInfo;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.mapapi.search.MKSearch;
import com.baidu.mapapi.search.MKSearchListener;
import com.baidu.mapapi.search.MKShareUrlResult;
import com.baidu.mapapi.search.MKSuggestionInfo;
import com.baidu.mapapi.search.MKSuggestionResult;
import com.baidu.mapapi.search.MKTransitRouteResult;
import com.baidu.mapapi.search.MKWalkingRouteResult;
/**
* 演示poi搜索功能
*/
public class PoiSearchActivity extends Activity {
private MapView mMapView = null;
private MKSearch mSearch = null; // 搜索模塊,也可去掉地圖模塊獨(dú)立使用
/**
* 搜索關(guān)鍵字輸入窗口
*/
private AutoCompleteTextView keyWorldsView = null;
private ArrayAdapter<String> sugAdapter = null;
private int load_Index;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DemoApplication app = (DemoApplication) this.getApplication();
if (app.mBMapManager == null) {
app.mBMapManager = new BMapManager(this);
app.mBMapManager.init(DemoApplication.strKey,
new DemoApplication.MyGeneralListener());
}
setContentView(R.layout.activity_poisearch);
mMapView = (MapView) findViewById(R.id.bmapView);
mMapView.getController().enableClick(true);
mMapView.getController().setZoom(12);
// 初始化搜索模塊,注冊(cè)搜索事件監(jiān)聽(tīng)
mSearch = new MKSearch();
mSearch.init(app.mBMapManager, new MKSearchListener() {
// 在此處理詳情頁(yè)結(jié)果
@Override
public void onGetPoiDetailSearchResult(int type, int error) {
if (error != 0) {
Toast.makeText(PoiSearchActivity.this, "抱歉,未找到結(jié)果",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(PoiSearchActivity.this, "成功,查看詳情頁(yè)面",
Toast.LENGTH_SHORT).show();
}
}
/**
* 在此處理poi搜索結(jié)果
*/
public void onGetPoiResult(MKPoiResult res, int type, int error) {
// 錯(cuò)誤號(hào)可參考MKEvent中的定義
if (error != 0 || res == null) {
Toast.makeText(PoiSearchActivity.this, "抱歉,未找到結(jié)果",
Toast.LENGTH_LONG).show();
return;
}
// 將地圖移動(dòng)到第一個(gè)POI中心點(diǎn)
if (res.getCurrentNumPois() > 0) {
// 將poi結(jié)果顯示到地圖上
MyPoiOverlay poiOverlay = new MyPoiOverlay(
PoiSearchActivity.this, mMapView, mSearch);
poiOverlay.setData(res.getAllPoi());
mMapView.getOverlays().clear();
mMapView.getOverlays().add(poiOverlay);
mMapView.refresh();
// 當(dāng)ePoiType為2(公交線路)或4(地鐵線路)時(shí), poi坐標(biāo)為空
for (MKPoiInfo info : res.getAllPoi()) {
if (info.pt != null) {
mMapView.getController().animateTo(info.pt);
break;
}
}
} else if (res.getCityListNum() > 0) {
// 當(dāng)輸入關(guān)鍵字在本市沒(méi)有找到,但在其他城市找到時(shí),返回包含該關(guān)鍵字信息的城市列表
String strInfo = "在";
for (int i = 0; i < res.getCityListNum(); i++) {
strInfo += res.getCityListInfo(i).city;
strInfo += ",";
}
strInfo += "找到結(jié)果";
Toast.makeText(PoiSearchActivity.this, strInfo,
Toast.LENGTH_LONG).show();
}
}
public void onGetDrivingRouteResult(MKDrivingRouteResult res,
int error) {
}
public void onGetTransitRouteResult(MKTransitRouteResult res,
int error) {
}
public void onGetWalkingRouteResult(MKWalkingRouteResult res,
int error) {
}
public void onGetAddrResult(MKAddrInfo res, int error) {
}
public void onGetBusDetailResult(MKBusLineResult result, int iError) {
}
/**
* 更新建議列表
*/
@Override
public void onGetSuggestionResult(MKSuggestionResult res, int arg1) {
if (res == null || res.getAllSuggestions() == null) {
return;
}
sugAdapter.clear();
for (MKSuggestionInfo info : res.getAllSuggestions()) {
if (info.key != null)
sugAdapter.add(info.key);
}
sugAdapter.notifyDataSetChanged();
}
@Override
public void onGetShareUrlResult(MKShareUrlResult result, int type,
int error) {
}
});
keyWorldsView = (AutoCompleteTextView) findViewById(R.id.searchkey);
sugAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line);
keyWorldsView.setAdapter(sugAdapter);
/**
* 當(dāng)輸入關(guān)鍵字變化時(shí),動(dòng)態(tài)更新建議列表
*/
keyWorldsView.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
}
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
if (cs.length() <= 0) {
return;
}
String city = ((EditText) findViewById(R.id.city)).getText()
.toString();
/**
* 使用建議搜索服務(wù)獲取建議列表,結(jié)果在onSuggestionResult()中更新
*/
mSearch.suggestionSearch(cs.toString(), city);
}
});
}
@Override
protected void onPause() {
mMapView.onPause();
super.onPause();
}
@Override
protected void onResume() {
mMapView.onResume();
super.onResume();
}
@Override
protected void onDestroy() {
mMapView.destroy();
super.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mMapView.onRestoreInstanceState(savedInstanceState);
}
/**
* 影響搜索按鈕點(diǎn)擊事件
*
* @param v
*/
public void searchButtonProcess(View v) {
EditText editCity = (EditText) findViewById(R.id.city);
EditText editSearchKey = (EditText) findViewById(R.id.searchkey);
mSearch.poiSearchInCity(editCity.getText().toString(), editSearchKey
.getText().toString());
}
public void goToNextPage(View v) {
// 搜索下一組poi
int flag = mSearch.goToPoiPage(++load_Index);
if (flag != 0) {
Toast.makeText(PoiSearchActivity.this, "先搜索開始,然后再搜索下一組數(shù)據(jù)",
Toast.LENGTH_SHORT).show();
}
}
}

布局XML(activity_poisearch):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="在" >
</TextView>
<EditText
android:id="@+id/city"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="北京" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="市內(nèi)找" >
</TextView>
<AutoCompleteTextView
android:id="@+id/searchkey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.88"
android:text="餐廳" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:orientation="horizontal" >
<Button
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="12"
android:background="@drawable/button_style"
android:onClick="searchButtonProcess"
android:padding="10dip"
android:text="開始" />
<Button
android:id="@+id/map_next_data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="12"
android:background="@drawable/button_style"
android:onClick="goToNextPage"
android:padding="10dip"
android:text="下一組數(shù)據(jù)" />
</LinearLayout>
<com.baidu.mapapi.map.MapView
android:id="@+id/bmapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" />
</LinearLayout>

MyPoiOverlay類

package com.home;
import android.app.Activity;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.PoiOverlay;
import com.baidu.mapapi.search.MKPoiInfo;
import com.baidu.mapapi.search.MKSearch;
public class MyPoiOverlay extends PoiOverlay {
MKSearch mSearch;
public MyPoiOverlay(Activity activity, MapView mapView, MKSearch search) {
super(activity, mapView);
mSearch = search;
}
@Override
protected boolean onTap(int i) {
super.onTap(i);
MKPoiInfo info = getPoi(i);
if (info.hasCaterDetails) {
mSearch.poiDetailSearch(info.uid);
}
return true;
}
}

在配置文件中要比之前多配置一個(gè)activity,不然沒(méi)法查看詳細(xì)界面,這是百度SDK jar中提供的類:

<activity
android:name="com.baidu.mapapi.search.PlaceCaterActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar" >
</activity>

Application類同之前。

相關(guān)文章

  • WebView設(shè)置WebViewClient的方法

    WebView設(shè)置WebViewClient的方法

    這篇文章主要介紹了 WebView設(shè)置WebViewClient的方法的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • Android?Gradle?三方依賴管理詳解

    Android?Gradle?三方依賴管理詳解

    這篇文章主要介紹了Android?Gradle?三方依賴管理詳解,Gradle的依賴管理是一個(gè)從開始接觸Android開發(fā)就一直伴隨著我們的問(wèn)題,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-08-08
  • Android獲得當(dāng)前正在顯示的activity類名的方法

    Android獲得當(dāng)前正在顯示的activity類名的方法

    這篇文章主要介紹了Android獲得當(dāng)前正在顯示的activity類名的方法,分析了權(quán)限的修改與Java代碼的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)

    Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)

    這篇文章主要為大家詳細(xì)介紹了Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • 詳談Android編譯命令

    詳談Android編譯命令

    本文給大家詳細(xì)介紹了Android中常用的編譯命令、用法以及注意事項(xiàng),非常的詳細(xì),有需要的小伙伴可以參考下
    2016-03-03
  • Kotlin 編程三分鐘入門

    Kotlin 編程三分鐘入門

    一個(gè)多月以來(lái)Kotlin從入門到現(xiàn)在,堅(jiān)持用來(lái)開發(fā)的切身感受。因?yàn)檎Z(yǔ)法與Java的區(qū)別挺大的一開始很想放棄,如果不是因?yàn)轫?xiàng)目在使用,想必很少人會(huì)嘗試這樣一門小眾語(yǔ)言,但是習(xí)慣后會(huì)發(fā)現(xiàn)這些年究竟浪費(fèi)多少時(shí)間在寫無(wú)用的Java代碼了
    2017-05-05
  • android圖片圓角、圖片去色處理示例

    android圖片圓角、圖片去色處理示例

    這篇文章主要介紹了android圖片圓角、圖片去色處理示例,需要的朋友可以參考下
    2014-05-05
  • Flutter 仿微信支付界面

    Flutter 仿微信支付界面

    網(wǎng)傳微信支付頁(yè)面的第三方鏈接一個(gè)格子需要廣告費(fèi)1一個(gè)億,微信支付頁(yè)非常適合做功能導(dǎo)航,本篇使用 ListView和 GridView 模仿了微信支付的頁(yè)面,同時(shí)介紹了如何裝飾一個(gè)組件的背景和邊緣樣式。
    2021-05-05
  • Android如何創(chuàng)建自定義ActionBar

    Android如何創(chuàng)建自定義ActionBar

    這篇文章主要教大家如何創(chuàng)建自定義的ActionBar,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)

    Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)

    這篇文章主要為大家詳細(xì)介紹了Android代碼實(shí)現(xiàn)AdapterViews和RecyclerView無(wú)限滾動(dòng)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-07-07

最新評(píng)論

济南市| 文成县| 嫩江县| 博野县| 乐业县| 榆中县| 蒙阴县| 新龙县| 台山市| 阳春市| 商河县| 常山县| 通江县| 宣汉县| 正定县| 陕西省| 宁城县| 临西县| 西乡县| 剑河县| 昭平县| 泰顺县| 陇西县| 垦利县| 镶黄旗| 长寿区| 永新县| 两当县| 响水县| 镇坪县| 磴口县| 永兴县| 兰坪| 三穗县| 绥棱县| 重庆市| 和顺县| 丹凤县| 京山县| 宽甸| 科技|