Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 你知道在地图上画画的工具吗_Json_Google Maps_Google Maps Api 3 - Fatal编程技术网

Json 你知道在地图上画画的工具吗

Json 你知道在地图上画画的工具吗,json,google-maps,google-maps-api-3,Json,Google Maps,Google Maps Api 3,我正在寻找一个工具,从谷歌地图api(我发现了一些)在地图上画一个多边形,但我想让你得到所有的多边形点的坐标。因为目前我只能逐点或以Json为例获取多边形的坐标 你知道这样的事情吗?经过更多的研究,我发现这对我来说是有效的: 以下是解决方案的代码: //var myPolygon; function initialize() { // Map Center var myLatLng = new google.maps.LatLng(33.5190755, -111.9253654);

我正在寻找一个工具,从谷歌地图api(我发现了一些)在地图上画一个多边形,但我想让你得到所有的多边形点的坐标。因为目前我只能逐点或以Json为例获取多边形的坐标

你知道这样的事情吗?

经过更多的研究,我发现这对我来说是有效的:
以下是解决方案的代码:

//var myPolygon;
function initialize() {
  // Map Center
  var myLatLng = new google.maps.LatLng(33.5190755, -111.9253654);
  // General Options
  var mapOptions = {
    zoom: 12,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.RoadMap
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);
  // Polygon Coordinates
  var triangleCoords = [
    new google.maps.LatLng(33.5362475, -111.9267386),
    new google.maps.LatLng(33.5104882, -111.9627875),
    new google.maps.LatLng(33.5004686, -111.9027061)
  ];
  // Styling & Controls
  myPolygon = new google.maps.Polygon({
    paths: triangleCoords,
    draggable: true, // turn off if it gets annoying
    editable: true,
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35
  });

  myPolygon.setMap(map);
  //google.maps.event.addListener(myPolygon, "dragend", getPolygonCoords);
  google.maps.event.addListener(myPolygon.getPath(), "insert_at", getPolygonCoords);
  //google.maps.event.addListener(myPolygon.getPath(), "remove_at", getPolygonCoords);
  google.maps.event.addListener(myPolygon.getPath(), "set_at", getPolygonCoords);
}

//Display Coordinates below map
function getPolygonCoords() {
  var len = myPolygon.getPath().getLength();
  var htmlStr = "";
  for (var i = 0; i < len; i++) {
    htmlStr += "new google.maps.LatLng(" + myPolygon.getPath().getAt(i).toUrlValue(5) + "), ";
    //Use this one instead if you want to get rid of the wrap > new google.maps.LatLng(),
    //htmlStr += "" + myPolygon.getPath().getAt(i).toUrlValue(5);
  }
  document.getElementById('info').innerHTML = htmlStr;
}
function copyToClipboard(text) {
  window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
}
///var myPolygon;
函数初始化(){
//地图中心
var mylatng=new google.maps.LatLng(33.5190755,-111.9253654);
//一般选择
变量映射选项={
缩放:12,
中心:myLatLng,
mapTypeId:google.maps.mapTypeId.RoadMap
};
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
//多边形坐标
var triangleCoords=[
新的google.maps.LatLng(33.5362475,-111.9267386),
新google.maps.LatLng(33.5104882,-111.9627875),
新google.maps.LatLng(33.5004686,-111.9027061)
];
//样式和控件
myPolygon=新建google.maps.Polygon({
路径:三角形门,
draggable:true,//如果它变得烦人,请关闭它
是的,
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:2,
填充颜色:'#FF0000',
不透明度:0.35
});
myPolygon.setMap(map);
//google.maps.event.addListener(myPolygon,“dragend”,getpolygords);
google.maps.event.addListener(myPolygon.getPath(),“insert_at”,getPolygords);
//google.maps.event.addListener(myPolygon.getPath(),“remove_at”,getPolygonWord);
google.maps.event.addListener(myPolygon.getPath(),“set_at”,getPolygords);
}
//在地图下面显示坐标
函数getPolygords(){
var len=myPolygon.getPath().getLength();
var htmlStr=“”;
对于(变量i=0;inew google.maps.LatLng(),请使用此选项,
//htmlStr+=“”+myPolygon.getPath().getAt(i).toUrlValue(5);
}
document.getElementById('info').innerHTML=htmlStr;
}
功能copyToClipboard(文本){
窗口提示(“复制到剪贴板:Ctrl+C,输入”,文本);
}


拖动或重新塑造坐标以显示在下方()
液化天然气
复制到剪贴板
<body onload="initialize()">
  <h3>Drag or re-shape for coordinates to display below (<a href="https://github.com/jeremy-hawes/google-maps-coordinates-polygon-tool">Github</a>)</h3>
  <h3><a href="http://codepen.io/jhawes/blog/creating-a-real-estate-polygon-tool">See blog post</a></h3>
  <div id="map-canvas"></div>
  <div class="lngLat"><span class="one">Lat</span><span class="two">,Lng</span></div>
</body>
<button id="clipboard-btn" onclick="copyToClipboard(document.getElementById('info').innerHTML)">Copy to Clipboard</button>
<textarea id="info"></textarea>