How to detect if a point is in a Circle?

前端 未结 6 772
广开言路
广开言路 2020-12-02 00:26

How can I test if a LatLng point is within the bounds of a circle? (Google Maps JavaScript v3)

The getBounds() method returns the bounding box for the circle, which

6条回答
  •  隐瞒了意图╮
    2020-12-02 01:04

    You might use the Circle object to show it;

    new google.maps.Circle({
                map : map,
                center : new google.maps.LatLng(lat,lng),
                strokeColor:'#00FFCC',
                strokeWeight:2,
                fillOpacity:0,
                radius:radiusm
            });
    

    And apply the Pythagorean theorem to coordinates: but in this case to make it a "real" circle since the ration between 1° of lat and longitude varies across latitudes, you should at the very least adjust them like:

    var kmRadius = 100; //(radius of 100 km)
    var lat_gap = kmRadius/111.1;
    var lng_gap = lat_gap / Math.cos(lat / (Math.PI/180));
    

提交回复
热议问题