The Google WebService API is meant for server side GeoCoding , that url you have is to be sent from the sever, that is why it contains a key, you would not put that key anywhere in the client facing code.
there is another API called Google Maps Javascript API V3 , this is the one you use to make requests client side . There are Geocode Examples on the site of to do that :
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.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('Geocode was not successful for the following reason: ' + status);
}
});
}
see the first line getElementById()
that is where you would put the ID of your element , which was your original question .
You do realize that this is all for getting the Timezone of an address that the user entered? right, you can probably make them choose a Timezone while they are entering an address.
if you simply just want the user's local timezone , well then that is much much easier , just this:
// this is offset from UTC time
var offset = new Date().getTimezoneOffset();
Best Answer
I had the same issue and I found this.
On the url, it requires the server key in the end and not the api key for the app.
So Basically, you just add the server key in the end of the URL like this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&sensor=true&key=SERVERKEY
Now, to obtain the server key, just follow these steps:
1) Go to Developer Console https://code.google.com/apis/console/
2) In the Credentials, under Public API Access, Create New key
3) Select the server key from the option.
4) Enter your IP Address on the field and if you have more ip addresses, you can just add on every single line.NOTE: Enter the IP Address only when you want to use it for your testing purpose. Else leave the IP Address section blank.
5) Once you are done, click create and your new Server Key will be generated and you can then add that server key to your URL.
Last thing is that, instead of putting the sensor=true in the middle of the URL, you can add it in the end like this:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=yourlatitude,yourlongitude&radius=5000&key=SERVERKEY&sensor=true
This will definitely solve the issue and just remember to use the server key for
Places API
.EDIT
I believe the web URL has changed in the past years. You can access developers console from here now - https://console.developers.google.com/apis/dashboard
Hope this answer will help you and other viewers. Good Luck .. :)