我是一个新手开发者google map api web应用程序,我有一个问题。什么等式(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;
感谢您的回答。
答案 0 :(得分:1)
假设至少(x0,y0)(x1,y1)和(x3,y3)已知,则:
if( x0>x3 && x0<x1 && y0>y3 && y0<y1 ) {
//(x0,y0) is in the rectangle
}
答案 1 :(得分:0)
我假设你正在使用google.maps.Rectangle类(你没有向我们展示你的任何代码,所以我可能错了,但这是合乎逻辑的。)
然后,您可以调用矩形对象上的getBounds()
函数来获取其LatLngBounds。
然后在该LatLngBounds对象上,您可以调用contains()
函数来确定它是否包含您的点的坐标。