-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
120 lines (76 loc) · 3.4 KB
/
test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!DOCTYPE html>
<html>
<head>
<title>Place Autocomplete Address Form</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
</head>
<body>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBGZYenfvLUtqSqpRZ8-1wi8btmMZUyffE&libraries=places&callback=initAutocomplete"
async defer></script>
<div id="locationField">
<input id="autocomplete" placeholder="Enter your address" type="text"></input>
</div>
<script>
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.
// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places">
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
function initAutocomplete() {
// Create the autocomplete object, restricting the search to geographical
// location types.
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
console.log(place);
/*for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}*/
/*// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
/*if (componentForm[addressType]) {
//var val = place.address_components[i][componentForm[addressType]];
//document.getElementById(addressType).value = val;
}
}*/
}
</script>
</body>
</html>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBGZYenfvLUtqSqpRZ8-1wi8btmMZUyffE&libraries=places&callback=initAutocomplete"
async defer></script>
<script>
var placeSearch, autocomplete;
function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
document.getElementById("latitude").value = place["geometry"]["viewport"]["l"]["j"]
document.getElementById("longitude").value = place["geometry"]["viewport"]["j"]["j"]
}
</script>