在Google地图中的标记周围获取javascript中8点的经度 [英] Get the latlong of 8 points in javascript around a marker in Google map

查看:68
本文介绍了在Google地图中的标记周围获取javascript中8点的经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在放置在Google地图上的标记周围x米的x米处获得8个位置的经纬度.请参考图片以获取想法.

I want to get the lat long of 8 locations at a distance of x meters around a marker placed on google maps. Please refer to the image to get an idea.

基本上我想在放置的标记周围得到一个由8个位置(N,NE,E,SE,S,SW,W,NW)组成的数组.这些点距标记的距离可以是x米.

Basically I want to get an Array of 8 Locations(N, NE, E, SE, S, SW, W, NW) arounds the placed marker. These points can be of x meter from the marker.

推荐答案

一种选择是使用

One option is to use the geometry library computeOffset method to compute positions at the desired distance from the center point every 45 degrees:

代码段:

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  var bounds = new google.maps.LatLngBounds();
  var centerPt = map.getCenter();
  var marker = new google.maps.Marker({
    position: centerPt,
    map: map
  })
  for (var angle = 0, i = 0; angle < 360; angle += 45, i++) {
    var marker = new google.maps.Marker({
      position: google.maps.geometry.spherical.computeOffset(centerPt, 100, angle),
      map: map,
      title: "marker #" + i + ", at " + angle + " degrees"
    })
    bounds.extend(marker.getPosition());
  }
  map.fitBounds(bounds);

}
google.maps.event.addDomListener(window, "load", initialize);

html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>

这篇关于在Google地图中的标记周围获取javascript中8点的经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆