如何在Google地图中确定Radius?

时间:2018-02-16 12:03:20

标签: javascript google-maps

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 20,
    center:this.cityHallLocation ,
    disableDefaultUI : true,
    styles:[{"featureType":"landscape","stylers":[{"hue":"#FFBB00"},{"saturation":43.400000000000006},{"lightness":37.599999999999994},{"gamma":1}]},{"featureType":"road.highway","stylers":[{"hue":"#FFC200"},{"saturation":-61.8},{"lightness":45.599999999999994},{"gamma":1}]},{"featureType":"road.arterial","stylers":[{"hue":"#FF0300"},{"saturation":-100},{"lightness":51.19999999999999},{"gamma":1}]},{"featureType":"road.local","stylers":[{"hue":"#FF0300"},{"saturation":-100},{"lightness":52},{"gamma":1}]},{"featureType":"water","stylers":[{"hue":"#0078FF"},{"saturation":-13.200000000000003},{"lightness":2.4000000000000057},{"gamma":1}]},{"featureType":"poi","stylers":[{"hue":"#00FF6A"},{"saturation":-1.0989010989011234},{"lightness":11.200000000000017},{"gamma":1}]}],
});

var marker = new google.maps.Marker({
    position: this.cityHallLocation,
    map: map,
});

如何确定我是否在谷歌地图中的正确半径。例如,我希望特定位置的特定半径为20,我想确定我是否在20米处,然后在该位置显示标记。对不起,我是谷歌地图的新手。

1 个答案:

答案 0 :(得分:0)

您需要使用库geolib或替代lib https://www.npmjs.com/package/geolib

geolib.isPointInCircle(object latlng, object center, integer radius)

例如

// checks if 51.525, 7.4575 is within a radius of 5km from 51.5175, 7.4678
geolib.isPointInCircle(
    {latitude: 51.525, longitude: 7.4575},
    {latitude: 51.5175, longitude: 7.4678},
    5000
);