-
-
Save nevosegal/5757467 to your computer and use it in GitHub Desktop.
Simple google maps implementation including a search field Just add API key and Default address.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
height: 100%; | |
} | |
body { | |
height: 100%; | |
margin: 0; | |
padding: 0; | |
} | |
#map-canvas{ | |
height: 100%; | |
} | |
.textBox{ | |
padding:0; | |
width:15%; | |
margin:10px auto 0 auto; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
</head> | |
<body> | |
<div class="textBox"> | |
<input type="text" id="address" value=""> | |
<input type="button" value="Search" onClick="codeAddress()"></div> | |
<div id="map-canvas"></div> | |
<script type="text/javascript" | |
src="https://maps.googleapis.com/maps/api/js?key=API_KEY&sensor=true"></script> | |
<script type="text/javascript" src="maps.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map, myGeocoder, initialAddress, address; | |
function initialize() { | |
myGeocoder = new google.maps.Geocoder(); | |
address = "DEFAULT ADDRESS"; | |
myGeocoder.geocode({'address': address}, function (results, status) { | |
map.setCenter(results[0].geometry.location); | |
}); | |
var mapOptions = { | |
'zoom':14, | |
'mapTypeId': google.maps.MapTypeId.ROADMAP | |
}; | |
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); | |
} | |
function codeAddress() { | |
address = document.getElementById('address').value; | |
myGeocoder.geocode({'address': address}, function (results, status) { | |
if (status === google.maps.GeocoderStatus.OK) { | |
map.setCenter(results[0].geometry.location); | |
var marker = new google.maps.Marker({ | |
'map': map, | |
'position': results[0].geometry.location | |
}); | |
} else{ | |
alert("No results found because: " + status); | |
} | |
}); | |
} | |
initialize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment