我在Javascript中有这个代码,它工作正常..现在我想在rails中做同样的事情。我想检查给定的多边形是否给定纬度和经度。我检查了ruby-kml,georuby和porth-kml宝石,但没有得到任何相关的东西。
<script type="text/javascript">
var geoXml = null;
var flag = 0;
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
var address = "<%= current_user.present? ? current_user.full_address : '' %>"
var myOptions = {
zoom: 12,
mapTypeControl: true,
mapTypeControlOptions:{style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
navigationControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
infowindow = new google.maps.InfoWindow({size: new google.maps.Size(150,50)});
$(document).ready(function() {
load_map();
});
function load_map() {
geoXml = new geoXML3.parser({map: map, singleInfoWindow: true, infoWindow: infowindow});
geoXml.parse("<%= @resturant.district.kml_url %>");
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var point = results[0].geometry.location;
for (var i=0; i<geoXml.docs[0].gpolygons.length; i++) {
if (geoXml.docs[0].gpolygons[i].Contains(point)) {
flag = 1;
i = 999;
}
}
if (flag!=1){
$(".link_modal").attr("data-target","#map_modal");}
}
}else {
return false;
}
});
}
</script>