Вы можете использовать библиотеку сферической геометрии, чтобы нарисовать треугольник с вершинами в 250 метрах от геокодированной точки в 0 градусов (север), 120 градусов (юго-восток) и -120 градусов (юго-запад).
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('valtxtaddres').value;
console.log("Address is:" + address);
if (address != '') {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var triangle1 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, 0);
var triangle2 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, 120);
var triangle3 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, -120);
var triangleCoords = [triangle1, triangle2, triangle3];
myPolygon = new google.maps.Polygon({
path: triangleCoords,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
myPolygon.setMap(gmap);
}
});
}
подтверждение концепции скрипта
фрагмент кода:
function initialize() {
var gmap = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var geocoder = new google.maps.Geocoder();
var address = document.getElementById('valtxtaddres').value;
console.log("Address is:" + address);
if (address != '') {
geocoder.geocode({
'address': address
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mark = new google.maps.Marker({
position: results[0].geometry.location,
map: gmap,
title: "C",
icon: {
url: "https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle.png",
size: new google.maps.Size(7, 7),
anchor: new google.maps.Point(3.5, 3.5)
}
});
var triangle1 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, 0);
var triangle2 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, 120);
var triangle3 = google.maps.geometry.spherical.computeOffset(results[0].geometry.location, 250, -120);
console.log("triangle1 is:" + triangle1.toUrlValue(6));
console.log("triangle2 is:" + triangle2.toUrlValue(6));
console.log("triangle3 is:" + triangle3.toUrlValue(6));
var triangleCoords = [triangle1, triangle2, triangle3];
myPolygon = new google.maps.Polygon({
path: triangleCoords,
// draggable: true, // turn off if it gets annoying
// editable: true,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
myPolygon.setMap(gmap);
}
});
}
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#map_canvas {
height: 90%;
width: 100%;
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<input id="valtxtaddres" value="Palo Alto, CA" />
<div id="map_canvas"></div>