-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (25 loc) · 1.1 KB
/
script.js
File metadata and controls
26 lines (25 loc) · 1.1 KB
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
/**
* Converts given address to geocode using Google Maps Geocoding API
* https://developers.google.com/maps/documentation/geocoding/intro
*
* @version 0.1
* @author Allar Vendla <allarvendla@gmail.com>
*/
var inputAddress = window.location.href.match(/address=(.*)/);
$(document).ready(function () {
if (inputAddress !== null && inputAddress[1] !== "") {
var jsonFeed = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + inputAddress[1];
$.getJSON(jsonFeed, function (data) {
if (data.status !== "ZERO_RESULTS"){
var address = data.results[0].formatted_address;
var latitude = data.results[0].geometry.location.lat;
var longitude = data.results[0].geometry.location.lng;
$('#output').append(address + "<br />" + "Latitude: " + latitude + "<br />" + "Longitude: " + longitude);
} else {
$('#output').append(inputAddress[1].replace(/\+/g, " ") + " <--: This is not a valid address!");
}
});
} else {
$('#output').append("Insert an address");
}
});