/
google_api.html
64 lines (51 loc) · 1.72 KB
/
google_api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#map-canvas {
width: 770px;
height: 481px;
}
</style>
</head>
<body>
<!-- div to hold map -->
<div id="map-canvas"></div>
<!-- Load the Google Maps API [DON'T FORGET TO USE A KEY] -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDjVvV7Jl6KFNUUhWXqURX6rX3kzjIrWhg"></script>
<!-- Script to show address on map -->
<script type="text/javascript">
(function() {
"use strict";
// Set our map options
var mapOptions = {
// Set the zoom level
zoom: 19,
// This sets the center of the map at our location
center: {
lat: 29.426791,
lng: -98.489602
}
};
// Render the map
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var geocoder = new google.maps.Geocoder();
// Include code from previous example
// Set our address to geocode
var address = "1003 Olivia view, San Antonio, TX, 78260";
// Init geocoder object
var geocoder = new google.maps.Geocoder();
// Geocode our address
geocoder.geocode({ "address": address }, function(results, status) {
// Check for a successful result
if (status == google.maps.GeocoderStatus.OK) {
// Recenter the map over the address
map.setCenter(results[0].geometry.location);
} else {
// Show an error message with the status if our request fails
alert("Geocoding was not successful - STATUS: " + status);
}
});
})();
</script>
</body>