Skip to content

Instantly share code, notes, and snippets.

/gist:8393151
Created Jan 13, 2014

Embed
What would you like to do?
LineString and Polygon intersect on google map
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
// original code from: https://developers.google.com/maps/documentation/javascript/examples/polygon-simple
function initialize() {
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0, -180),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(42.049999, -96.25),
new google.maps.LatLng(38.08809796, -119.6092165),
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
var noFlyCoordinatesStr = "40.65:-114.07 40.21:-112.96 40:-112.66 39.4:-112.7 39.39:-113.28 39.68:-113.94 40.42:-114.26 40.6:-114.22";
var noFlyCoordinates = noFlyCoordinatesStr.split(" ").map(function( latlongStr){
var latlong = latlongStr.split(":")
return new google.maps.LatLng(latlong[0],latlong[1]);
})
var noFlyPath = new google.maps.Polyline({
path: noFlyCoordinates,
geodesic: true,
strokeColor: '#FF11111',
strokeOpacity: 1.0,
strokeWeight: 2
});
noFlyPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.