谷歌地图圈到多段线坐标数组 [英] google maps circle to polyline coordinate array

查看:154
本文介绍了谷歌地图圈到多段线坐标数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 google.maps.Circle 的对象获取多段线坐标数组
$ b




解决方案

google.maps.Circle不包含坐标数组。如果你想要一个圆形的google.maps.Polygon,你需要创建一个。

 函数drawCircle(point ,radius,dir){
var d2r = Math.PI / 180; //度数为弧度
var r2d = 180 / Math.PI; //弧度到度
var earthsradius = 3963; // 3963是以英里为单位的地球半径

var points = 32;

//找到lat / lon中的raidus
var rlat =(radius / earthsradius)* r2d;
var rlng = rlat / Math.cos(point.lat()* d2r);

var extp = new Array();
if(dir == 1){
var start = 0;
var end = points + 1; //这里另外一个确保我们连接路径
} else {
var start = points + 1;
var end = 0;

for(var i = start;(dir == 1?i< end:i> end); i = i + dir)
{
var theta = Math.PI *(i /(points / 2));
ey = point.lng()+(rlng * Math.cos(theta)); //中心a +半径x * cos(theta)
ex = point.lat()+(rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push(new google.maps.LatLng(ex,ey));
}
return extp;
}

var circle = new google.maps.Polygon({
map:map,
paths:[drawCircle(new google.maps.LatLng(-33.9 ,151.2),100,1)],
strokeColor:#0000FF,
strokeOpacity:0.8,
strokeWeight:2,
fillColor:#FF0000,
fillOpacity:0.35
});

例子


how to get array of polyline coordinates from google.maps.Circle's object

there is no api doc entry about that

解决方案

A google.maps.Circle doesn't contain an array of coordinates. If you want a google.maps.Polygon that is shaped like a circle, you need to make one.

function drawCircle(point, radius, dir) { 
  var d2r = Math.PI / 180;   // degrees to radians 
  var r2d = 180 / Math.PI;   // radians to degrees 
  var earthsradius = 3963; // 3963 is the radius of the earth in miles

  var points = 32; 

  // find the raidus in lat/lon 
  var rlat = (radius / earthsradius) * r2d; 
  var rlng = rlat / Math.cos(point.lat() * d2r); 

  var extp = new Array(); 
  if (dir==1) {
     var start=0;
     var end=points+1; // one extra here makes sure we connect the path
  } else {
     var start=points+1;
     var end=0;
  }
  for (var i=start; (dir==1 ? i < end : i > end); i=i+dir)  
  { 
     var theta = Math.PI * (i / (points/2)); 
     ey = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta) 
     ex = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta) 
     extp.push(new google.maps.LatLng(ex, ey)); 
  } 
  return extp;
}

var circle = new google.maps.Polygon({
               map: map,
               paths: [drawCircle(new google.maps.LatLng(-33.9,151.2), 100, 1)],
               strokeColor: "#0000FF",
               strokeOpacity: 0.8,
               strokeWeight: 2,
               fillColor: "#FF0000",
               fillOpacity: 0.35
});

Example

这篇关于谷歌地图圈到多段线坐标数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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