skip to main |
skip to sidebar
RSS Feeds
Technical interview questions for software engineers — languages, databases, cloud, DevOps, and CS fundamentals.
Technical interview questions for software engineers — languages, databases, cloud, DevOps, and CS fundamentals.
Technical interview questions for software engineers — languages, databases, web, cloud, DevOps, and fundamentals. Browse all topics.
Posted by Raj
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
function initialize() {
map = new google.maps.Map(document.getElementById("gmap"), {
zoom:13,
center: new google.maps.LatLng(18.520430, 73.856744),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
p = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
p.setMap(map);
p.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addMarker);
}
/** * Handles click events on a map, and adds a new point to the Polyline.*/
function addMarker(event) {
path.insertAt(path.length, event.latLng); //The path element used to draw polygon and polylines.
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
markers.splice(i, 1);
path.removeAt(i);
}
);
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
path.setAt(i, marker.getPosition());
}
);
}
function findAddress(address) {
if (!address)
var address=document.getElementById("address").value;
if ((address != '') && geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport)
map.fitBounds(results[0].geometry.viewport);
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
<html>
<title>Create Complex polygon on Gmap using Google Maps API v3</title>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var poly, map;
var markers = [];
var path = new google.maps.MVCArray;
var geocoder = new google.maps.Geocoder();
function initialize() {
map = new google.maps.Map(document.getElementById("gmap"), {
zoom:13,
center: new google.maps.LatLng(18.520430, 73.856744),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
p = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
p.setMap(map);
p.setPaths(new google.maps.MVCArray([path]));
google.maps.event.addListener(map, 'click', addMarker);
}
function addMarker(event) {
path.insertAt(path.length, event.latLng); //The path element used to draw polygon and polylines.
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', function() {
marker.setMap(null);
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
markers.splice(i, 1);
path.removeAt(i);
}
);
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, I = markers.length; i < I && markers[i] != marker; ++i);
path.setAt(i, marker.getPosition());
}
);
}
function findAddress(address) {
if (!address)
var address=document.getElementById("address").value;
if ((address != '') && geocoder) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (results && results[0] && results[0].geometry && results[0].geometry.viewport)
map.fitBounds(results[0].geometry.viewport);
} else {
alert("No results found");
}
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
}
</script>
</head>
<body style="margin:0px; padding:0px;" onLoad="initialize()">
Find Place: <input type="text" id="address"/><input type="button" value="Go" onClick="findAddress()">
<div id="gmap" style="width:100%; height: 580;"></div>
</body>
</html>