Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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
Javascript:在谷歌地图中获取Lat-Long之间的中点(质心)_Javascript_Jquery_Html_Google Maps - Fatal编程技术网

Javascript:在谷歌地图中获取Lat-Long之间的中点(质心)

Javascript:在谷歌地图中获取Lat-Long之间的中点(质心),javascript,jquery,html,google-maps,Javascript,Jquery,Html,Google Maps,我有一个基于谷歌地图的程序,可以根据用户输入计算面积。这是 HTML应该是这样的 <div class="google-maps" id="map" style="height: 400px; position: relative; border: 1px solid #CCC;"></div> <p>Length (red line): <span id="span-length">0</span> mt - Area

我有一个基于谷歌地图的程序,可以根据用户输入计算面积。这是

HTML应该是这样的

<div class="google-maps" id="map" style="height: 400px; position: relative; border: 1px solid #CCC;"></div>
    <p>Length (red line):
    <span id="span-length">0</span> mt - Area (grey area): <span id="span-area">0</span> mt2</p>
我尝试获取中点(质心)并返回长纬度值。有点像这样。问题是我试图得到中点(质心),但总是得到一个错误。它是这样返回的:

如果有人能帮助我,我将不胜感激
谢谢

您可以先声明LatLngBounds()对象,然后为每个标记扩展绑定对象:

    var bounds = new google.maps.LatLngBounds();
    var loc = measure.polygon.getPath().b;
    for (i = 0; i < loc.length; i++) {
        bounds.extend(new google.maps.LatLng(loc[i].lat(), loc[i].lng()));
    }

    var marker = new google.maps.Marker({
        position: bounds.getCenter(),
        map: map
    });
var-bounds=new google.maps.LatLngBounds();
var loc=measure.polygon.getPath().b;
对于(i=0;i

为什么你不能使用多边形的
bounds.getCenter()
(就像你链接到的示例)?@geocodezip我链接到的示例是原始示例,我尝试使用bounds组合这两个示例,但返回错误。也许这是一个更好的问题。哇,太棒了,我通过添加
jQuery(“#Lat”).val(bounds.getCenter().Lat())
jQuery(#Lng”).val(bounds.getCenter().Lng())
来获得Lat和Lng的值。谢谢,先生:)
    var bounds = new google.maps.LatLngBounds();
    var loc = measure.polygon.getPath().b;
    for (i = 0; i < loc.length; i++) {
        bounds.extend(new google.maps.LatLng(loc[i].lat(), loc[i].lng()));
    }

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