0

I use google maps and my question, how I can restrict scroll area on google maps? I use this method for restrict a rect area

mapDataView.getGoogleMap().setLatLngBoundsForCameraTarget(UIUtils.getLatLngBoundsFromCircle(circle));

    public static LatLngBounds getLatLngBoundsFromCircle(Circle circle){
        if(circle != null){
            return new LatLngBounds.Builder()
                    // external rectangle
//                    .include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius() * Math.sqrt(2), 45))
//                    .include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius() * Math.sqrt(2), 225))
                    //internal rectangle
                    .include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius(), 45))
                    .include(SphericalUtil.computeOffset(circle.getCenter(), circle.getRadius(), 225))
                    .build();
        }
        return null;
    }

But I can restrict only external or internal rectangle. Do you know, maybe google has some method for polygon restriction or something else. I've spent more than 3 days to find a solution. Thanks in advance. More info I create a custom marker and draw circle with radius, for example 100m, then I allow moving the marker in the circle

Alex Khotiun
  • 431
  • 4
  • 16
  • Possible duplicate of [How to convert a LatLng and a radius to a LatLngBounds in Android Google Maps API v2?](https://stackoverflow.com/questions/15319431/how-to-convert-a-latlng-and-a-radius-to-a-latlngbounds-in-android-google-maps-ap) – Karan Harsh Wardhan Mar 27 '19 at 06:00
  • setLatLngBoundsForCameraTarget will only accept rectangular target(on android sdk, javascript sdk supports circle target- you could use a webview if you really really need circle), you should compute the appropriate rectangle for the circle you want to create and display the map accordingly – Karan Harsh Wardhan Mar 27 '19 at 06:01
  • @kkarakk thanks for your reply. yes, I used that solution, but I really need circle. Yes now I have rectangle inside circle, but I have empty space inside circle. using webview mean that all my maps will work inside webview, it's not good solution. Maybe some third party library or some extension uses this feature – Alex Khotiun Mar 27 '19 at 06:29
  • can't you just embed the mapview and customize it to be circular? – Karan Harsh Wardhan Mar 27 '19 at 06:31
  • https://stackoverflow.com/questions/42528380/show-map-within-a-circle-round-layout/42530039?noredirect=1#comment72232935_42530039 like this – Karan Harsh Wardhan Mar 27 '19 at 06:33
  • @kkarakk no, unfortunately, your solution doesn't help me. I create a custom marker and draw circle with radius, for example 100m, then I allow moving the marker in the circle – Alex Khotiun Mar 27 '19 at 06:38
  • 1
    you should add what you've achieved to the question so people can help you out(code+image) – Karan Harsh Wardhan Mar 27 '19 at 06:39

0 Answers0