Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在谷歌地图Api V2 Android中搜索?_Android_Google Maps_Geolocation_Google Maps Markers_Google Maps Api 2 - Fatal编程技术网

如何在谷歌地图Api V2 Android中搜索?

如何在谷歌地图Api V2 Android中搜索?,android,google-maps,geolocation,google-maps-markers,google-maps-api-2,Android,Google Maps,Geolocation,Google Maps Markers,Google Maps Api 2,我正在开发一个Android应用程序,并使用谷歌地图API v2。 目前为止,此应用程序仍在运行,但我希望在地图中搜索路径: 截图: 我的代码: Position_mark = new LatLng(35.7008, 51.437); map.moveCamera(CameraUpdateFactory.newLatLngZoom(Position_mark, 15)); map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null)

我正在开发一个Android应用程序,并使用谷歌地图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);


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

您可以使用地理编码进行搜索或查看这个使用json解析GoogleMaps的漂亮教程


这个例子对我来说非常好..谢谢@Kavyan使用地理编码在谷歌地图中搜索位置并不好。因为它不能在所有设备上工作。@Segi它应该在能够访问Google Maps V2 API(通过Play Services提供)的相同设备上工作,因为使用的地理编码器是由地图驱动的
@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)));
}