代码之家  ›  专栏  ›  技术社区  ›  FernandoPaiva

如何使用GoogleMap源和目标?

  •  0
  • FernandoPaiva  · 技术社区  · 10 年前

    我正在尝试创建一个如何使用GoogleMap的方法。我要追踪源和目标的路线。为此,我有经度和纬度的源位置和目标位置。为此,我创建了两个属性。 source and target 源是我的位置,目标是我想去的地方。

    我该怎么做?如何在GoogleMap中追踪路线?

    public class FormComoChegarEmpresa extends Fragment{
        private MapView mapView;
        private GoogleMap map;
        private final String TAG = getClass().getSimpleName() + "->";
        private static Empresa empresa;
    
    
        //latitude longitude
        private Double sourceLat, sourceLong;
        private Double targetLat, targetLong;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.como_chegar_empresa, container, false);
    
            if(getArguments().getSerializable("empresa") != null){
                empresa = (Empresa)getArguments().getSerializable("empresa");
                targetLat = empresa.getEndereco().getLatitude();
                targetLong = empresa.getEndereco().getLongitude();
            }
    
            mapView = (MapView)view.findViewById(R.id.mapView);
            mapView.onCreate(savedInstanceState);
    
    
            map = mapView.getMap();
            if(map != null){
                map.getUiSettings().setMyLocationButtonEnabled(false);
                map.setMyLocationEnabled(true);
    
                //my location
                sourceLat = map.getMyLocation().getLatitude();
                sourceLong = map.getMyLocation().getLongitude();
    
                try {
                    MapsInitializer.initialize(this.getActivity());
                } catch (Exception e) {
                    Log.e(TAG, e.getLocalizedMessage());
                }
    
                // Updates the location and zoom of the MapView
                CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(sourceLat,
                        sourceLong), 10);
                map.animateCamera(cameraUpdate);
            }
    
    
            return  view;
        }
    
        @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
    
        }
    
        @Override
        public void onResume() {
            mapView.onResume();
            super.onResume();
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            mapView.onDestroy();
        }
    
        @Override
        public void onLowMemory() {
            super.onLowMemory();
            mapView.onLowMemory();
        }
    
    
    
    }
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   Farshad Kazemi    10 年前

    如果你要在 来源 & 目的地 ,您可以使用 This Labrary

    如果要从开始摄影机动画 来源 目的地 ,我不确定你的代码是否正确!只是我觉得你应该通过 目的地 进入 camera更新 来源 ...

    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(targetLat, targetLong), 10);