谷歌Map没有找到我搜索的所有地方

sczxawaw  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(154)

当我在我的搜索视图中搜索一个地方时,有时谷歌找不到任何东西并给我错误信息。例如:如果我搜索罗马,它会运行;如果我搜索罗马(意大利语),它不会运行。但如果我对威尼斯或威尼斯(意大利语)也这么做,这两种情况都适用。代码如下:
公共类googlemap在MapReadyCallback上扩展了fragmentactivity实现{

com.google.android.gms.maps.GoogleMap map;
SupportMapFragment mapFragment;
SearchView sv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.google_maps);
    sv = (SearchView)findViewById(R.id.sv_location);
    mapFragment=(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.google_map);

    DbHelperSupport dbS = new DbHelperSupport(getApplicationContext());
    DbHelperJourney dbJ = new DbHelperJourney(getApplicationContext());

    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {

            String location =sv.getQuery().toString();
            List<Address> addressList = new ArrayList<>();

            if(!location.equals("")){
                Geocoder geocoder = new Geocoder(getApplicationContext());
                try {
                    addressList=geocoder.getFromLocationName(location,1);
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
                Address address = addressList.get(0);
                LatLng latLng = new LatLng(address.getLatitude(),address.getLongitude());

                map.addMarker(new MarkerOptions().position(latLng).title(location));
                map.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,10));
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    mapFragment.getMapAsync(this);

    final Button back = (Button) findViewById(R.id.back_google_maps);
    final Intent goBack = new Intent(GoogleMap.this, Journey.class);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(goBack);
        }
    });

    final Button add = (Button)findViewById(R.id.add_google_maps);
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

           dbJ.add(dbS.read("nation"), sv.getQuery().toString());
           Toast.makeText(GoogleMap.this,"This place has been added to your journey in " + dbS.read("nation"), Toast.LENGTH_SHORT).show();
        }
    });

}

@Override
public void onMapReady(@NotNull com.google.android.gms.maps.GoogleMap googleMap) {
    map = googleMap;
}

}
错误在于,找不到它无法将arraylist的第一个元素“address address=addresslist.get(0);”提供给address对象的任何内容索引自动绑定。。。有什么问题吗?谢谢你的帮助

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题