0

我是一名新手开发人员谷歌地图 API 网络应用程序,我有一个问题。什么方程(Javascript)在矩形多边形区域中找到我的标记点,这是一个例子:

在此处输入图像描述

这是我的脚本:

$(document).ready(function(){
    $('#map_canvas').height($('#content').height());
});

var map;
var tableID = 'myid';
var auth = true;
var cloudData;
var authLink;
var rectangleCloud = new Array();

function initialize(){
  result = JSON.parse(token);
  getFeature(result.access_token);
  showMap(result.access_token);

}

function showMap(authResult) {
  // Create a new Google Maps API Map
  var mapOptions = {
    center: new google.maps.LatLng(13.74657604702232,100.53490161895752),
    zoom: 6,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("map_canvas"),
      mapOptions);
  //console.log(getFeatureById(mapsEngineLayer.featureId));+

  google.maps.event.addListener(mapsEngineLayer, 'bounds_changed', function() {
     map.fitBounds(mapsEngineLayer.get('bounds'));
  });

  //i think add equation at this.
  window.setTimeout(refreshToken, authResult.expires_in * 1000);

}

function getFeature(authResult){
   // List the details of a specific Google Maps Engine Map.
  var url = "https://www.googleapis.com/mapsengine/v1/tables/"+tableID+"/features";

  jQuery.ajax({
    url: url,
    dataType: 'json',
    headers: {
      'Authorization': 'Bearer ' + authResult
    },
    success: function(response) {
      // Log the details of the Map.  
      cloudData = response;
      console.log(cloudData.features);
      //this is a data callback from mapengine api
    },
    error: function(response) {
      response = JSON.parse(response.responseText);
      console.log("Error: ", response);
      window.location(authLink);
    }
  });
}

function loadScript() {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=visualization&language=th&callback=initialize';
  document.body.appendChild(script);
}

function createButtonAuth(){
  console.log("in");
  var inDiv = document.getElementById('mapWindown');
  var iDiv = document.createElement('div');
      iDiv.id = 'buttonAuth';
      iDiv.className = 'buttonAuth-style';
      iDiv.innerHTML = "<button  class='btn btn-large btn-block btn-primary' type='button'><a href='$authUrl'>Authorize this application</a></button>";
      iDiv.appendChild(inDiv);
}

window.onload = loadScript;

感谢您的任何回答。

4

2 回答 2

1

假设至少 (x0,y0) (x1,y1) 和 (x3,y3) 已知,则:

if( x0>x3 && x0<x1 && y0>y3 && y0<y1 ) {
    //(x0,y0) is in the rectangle
}
于 2013-10-08T08:04:56.933 回答
0

我假设您正在使用 google.maps.Rectangle 类(您没有向我们展示您的任何代码,所以我可能错了,但这是合乎逻辑的)。

然后,您可以在矩形对象上调用该getBounds()函数以获取其 LatLngBounds。

然后在该 LatLngBounds 对象上,您可以调用该contains()函数以确定它是否包含您的点的坐标。

于 2013-10-08T08:24:51.790 回答