Google Maps android get longitude-latitude by moving a marker in the map

后端 未结 4 809
囚心锁ツ
囚心锁ツ 2021-02-09 13:36

Hi i am developping an android application in which i need the user to choose a location by mouving a parker so i can get the informations i need exactly like this but in an and

4条回答
  •  后悔当初
    2021-02-09 14:25

    @Override
        public void onMapReady(GoogleMap googleMap)
        {
            mMap = googleMap;
    
    
            mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener()
            {
                @Override
                public void onCameraChange(CameraPosition cameraPosition)
                {
    
                    mCenterLatLong = cameraPosition.target;
                    mMap.clear();
    
                    try
                    {
    
                        Location mLocation = new Location("");
                        mLocation.setLatitude(mCenterLatLong.latitude);
                        mLocation.setLongitude(mCenterLatLong.longitude);
    
                        startIntentService(mLocation);
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            });
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
            {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
        }
    

提交回复
热议问题