如何在谷歌地图API第2版Android的搜索? [英] How to Search in Google Map Api V2 Android?

查看:127
本文介绍了如何在谷歌地图API第2版Android的搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,并使用谷歌地图API第2版。 该应用程序的工作,到目前为止,但我希望在地图上用路径搜索:

I'm developing an Android application and using GoogleMaps API v2. This application works so far but I want search in the map with a path:

截图:

我的codeS:

Position_mark = new LatLng(35.7008, 51.437);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(Position_mark, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
map.setOnMapClickListener(this);
map.setOnMapLongClickListener(this);
map.setOnMarkerDragListener(this);

...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //Used to put dark icons on light action bar

    mGoItem = menu.add(0, Delete_ITEM_ID, 0, null);
    mGoItem.setIcon(R.drawable.ic_launcher)
           .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    SearchView searchView = 
        new SearchView(getSupportActionBar().getThemedContext());
    searchView.setQueryHint("Search for Places…");
    searchView.setIconified(false);

    menu.add("Search")
        .setIcon(R.drawable.abs__ic_search)
        .setActionView(searchView)
        .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String newText) {
            return true;
        }

        /**
         * Called when the query text is changed by the user.
         * @param newText the new content of the query text field.
         * @return false if the SearchView should perform the 
         * default action of showing any suggestions if available, 
         * true if the action was handled by the listener.
         */
        @Override
        public boolean onQueryTextChange(String newText) {
            Toast.makeText(getApplicationContext(), newText, 1).show();
            return true;
        }
    });

    return true;
}

@Override
public void onMapClick(LatLng point) {
    // TODO Auto-generated method stub
    // tvLocInfo.setText(point.toString());
    map.animateCamera(CameraUpdateFactory.newLatLng(point));
    map.clear();

    Marker Kiel = map.addMarker(new MarkerOptions()
        .position(point)
        .title("Kiel")
        .snippet("Kiel is cool").draggable(true)
        .icon(BitmapDescriptorFactory
        .fromResource(R.drawable.ic_launcher)));
}

我用 ActionBarSherlock 搜索查看进行搜索。如何在Google地图API与路径不latitute或经度搜索?

I use ActionBarSherlock and SearchView for searching. How to search in GoogleMaps API with path not latitute or longitude?

推荐答案

您可以使用地理编码搜索或看到这个漂亮的教程,它使用JSON解析的GoogleMaps。

You can use geocoding to search or see this nice tutorial which uses json parsing GoogleMaps.

  • <一个href="http://wptrafficanalyzer.in/blog/adding-google-places-autocomplete-api-as-custom-suggestions-in-android-search-dialog/"相对=nofollow>添加谷歌的地方自动完成API在Android的搜索对话框
  • 自定义的建议
  • Adding Google Places Autocomplete API as custom suggestions in Android Search Dialog

这篇关于如何在谷歌地图API第2版Android的搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆