【问题标题】:android addmarker redirct to wrong positionandroid添加标记重定向到错误的位置
【发布时间】:2017-11-20 17:04:32
【问题描述】:

如果我将 log lat 的输出粘贴到 google maps 中,它会重定向到正确的位置,但 animateCamera() 会重定向到 google maps android 应用程序中的错误位置。请帮忙!

 public void onSearch(View view){
            Log.i("******************","in search function");
            EditText locationTf = (EditText)findViewById(R.id.editText);
            String location = locationTf.getText().toString();
            Log.i("Entered location:",location);
            if(location != null || location.equals("")){
                Log.i("In if statement","all condition are satisfied");
                Geocoder geocoder = new Geocoder(this);
                try {
                    addresses = geocoder.getFromLocationName(location,1);
                    Log.i("in try block",addresses.toString());
                } catch (IOException e) {
                    e.printStackTrace();
                }

                Address address = addresses.get(0);
                Log.i("after try catch block",address.toString());
                LatLng searchLatLng = new LatLng(address.getLatitude(),address.getLatitude());
                double logLat = address.getLatitude() ;
                double logLon = address.getLongitude() ;
                Log.i("********************","&&&&&&&&&&&&&&&&&&&&&&&&");
                Log.i(Double.toString(logLat),Double.toString(logLon));

                mMap.addMarker(new MarkerOptions().position(searchLatLng).title("Results"));
                mMap.animateCamera(CameraUpdateFactory.newLatLng(searchLatLng));
               // mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(searchLatLng, 10));
            }
            else {

            }

        }

【问题讨论】:

    标签: android camera location geocoder


    【解决方案1】:

    您正在通过 2 个纬度。

    LatLng(address.getLatitude(),address.getLatitude());
    

    代替

    LatLng(address.getLatitude(),address.getLongitude());
    

    【讨论】:

      猜你喜欢
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      • 2021-09-03
      • 2016-07-15
      • 1970-01-01
      相关资源
      最近更新 更多