- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-input.html
More file actions
Latest commit
29 lines (27 loc) · 926 Bytes
/
Copy pathexample-input.html
File metadata and controls
29 lines (27 loc) · 926 Bytes
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
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<inputname="address" id="input">
<scripttype="text/javascript">
$(document).ready(function(){
getLocation();
});
functiongetLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}
else{
alert("Geolocation is not supported by this browser.");
}
}
functionshowPosition(position){
// alert("Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude);
varlat=position.coords.latitude;
varlng=position.coords.longitude;
varlatlng=lat+","+lng;
varapikey="*********";
$.get("https://maps.googleapis.com/maps/api/geocode/json?latlng="+latlng+"&sensor=true&key="+apikey,function(data,status){
// alert("Data: " + data + "\nStatus: " + status);
varADDRESS=data.results[0].formatted_address;
$("#input").val(ADDRESS);
});
}
</script>