【问题标题】:How to Search in Google Map Api V2 Android?如何在 Google Map Api V2 Android 中搜索?
【发布时间】:2013-08-14 02:17:53
【问题描述】:

我正在开发一个 Android 应用程序并使用 GoogleMaps API v2。 此应用程序到目前为止工作,但我想在地图中搜索路径:

截图:

我的代码:

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)));
}

我使用ActionBarSherlockSearchView 进行搜索。如何在 GoogleMaps API 中搜索路径不是纬度或经度?

【问题讨论】:

    标签: android google-maps geolocation google-maps-markers google-maps-api-2


    【解决方案1】:

    您可以使用地理编码来搜索或查看这个使用 json 解析 GoogleMaps 的精彩教程。

    【讨论】:

    • 这个例子对我来说非常好..谢谢wptrafficanalyzer.in/blog/…
    • @Kavyan 使用地理编码在谷歌地图中搜索位置并不好。因为它不适用于所有设备..
    • @Segi 它应该在可以访问 Google Maps V2 API(可通过 Play 服务获得)的相同设备上工作,因为使用中的地理编码器由地图提供支持
    猜你喜欢
    • 2014-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多