JSFiddle - React, Tailwind, and code Playground
by brightonmike
HTML
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<input type="text" id="address1"/><input type="text" id="address2"/><input type="submit" id="init_map"/>
<div id="map_canvas">Enter locations and click Submit</div>
CSS
#map_canvas {
background:#ccc;
height:400px;
width:100%;
}
body { font:13px/1.231 sans-serif; *font-size:small;
background: rgb(210,210,210);
background: -moz-linear-gradient(top, rgba(210,210,210,1) 0%, rgba(230,230,230,1) 13%, rgba(217,217,217,1) 37%, rgba(227,227,227,1) 70%, rgba(227,227,227,1) 83%, rgba(212,212,212,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(210,210,210,1)), color-stop(13%,rgba(230,230,230,1)), color-stop(37%,rgba(217,217,217,1)), color-stop(70%,rgba(227,227,227,1)), color-stop(83%,rgba(227,227,227,1)), color-stop(100%,rgba(212,212,212,1)));
background: -webkit-linear-gradient(top, rgba(210,210,210,1) 0%,rgba(230,230,230,1) 13%,rgba(217,217,217,1) 37%,rgba(227,227,227,1) 70%,rgba(227,227,227,1) 83%,rgba(212,212,212,1) 100%);
background: -o-linear-gradient(top, rgba(210,210,210,1) 0%,rgba(230,230,230,1) 13%,rgba(217,217,217,1) 37%,rgba(227,227,227,1) 70%,rgba(227,227,227,1) 83%,rgba(212,212,212,1) 100%);
background: -ms-linear-gradient(top, rgba(210,210,210,1) 0%,rgba(230,230,230,1) 13%,rgba(217,217,217,1) 37%,rgba(227,227,227,1) 70%,rgba(227,227,227,1) 83%,rgba(212,212,212,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#d2d2d2', endColorstr='#d4d4d4',GradientType=0 );
background: linear-gradient(top, rgba(210,210,210,1) 0%,rgba(230,230,230,1) 13%,rgba(217,217,217,1) 37%,rgba(227,227,227,1) 70%,rgba(227,227,227,1) 83%,rgba(212,212,212,1) 100%);}
input[type="submit"] {
background: rgb(39,39,39);
background: -moz-linear-gradient(top, rgba(39,39,39,1) 0%, rgba(42,42,42,1) 46%, rgba(53,53,53,1) 46%, rgba(28,28,28,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(39,39,39,1)), color-stop(46%,rgba(42,42,42,1)), color-stop(46%,rgba(53,53,53,1)), color-stop(100%,rgba(28,28,28,1)));
background: -webkit-linear-gradient(top, rgba(39,39,39,1) 0%,rgba(42,42,42,1)...
JavaScript
var map,
bounds;
function initialize() {
var pinkParksStyles = [
{
featureType: "all",
stylers: [
{ saturation: -80 }
]
},{
featureType: "road.arterial",
elementType: "geometry",
stylers: [
{ hue: "#00ffee" },
{ saturation: 50 }
]
},{
featureType: "poi.business",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
{name: "Pink Parks"});
var myOptions = {
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
},
// List of locations, obviously this would be replaced by your input values
locations = [document.getElementById('address1').value, document.getElementById('address2').value];
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
bounds = new google.maps.LatLngBounds();
map.mapTypes.set('pink_parks', pinkMapType);
map.setMapTypeId('pink_parks');
addMarkers(locations);
// Set up geodesic polyline
var geodesicOptions = {
strokeColor: '#CC0099',
strokeOpacity: 0.7,
strokeWeight: 3,
geodesic: true
}
geodesic = new google.maps.Polyline(geodesicOptions);
geodesic.setMap(map);
}
// Geodesic origin
function addOrigin(location) {
var gPath = geodesic.getPath();
gPath.push(location);
}
// Geodesic destination
function addDestination(location) {
var gPath = geodesic.getPath();
gPath.push(location);
}
// addMarkers function, takes an array of plain english addresses, geocodes
// them and then adds as markers with the original address the title
function addMarkers(locations) {
var geocoder = new google.maps.Geocoder();
// Loop through locations array
for (var i = 0; i < locations.length; i++) {
// Use geocode service to find...