admin管理员组文章数量:1410737
I am trying to use the Google API time zones, and first you must geocode the address to get the lat/long for time zone. How would I go about doing this from a value in a textarea? 2 steps,
- convert textarea value to geocode example
+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY
- then use this lat/long to get the timezone example
.6034810,-119.6822510×tamp=1331161200&key=API_KEY?
<textarea id="phyaddr">
123 Address
Suite 1200
Houston TX 77008
USA
County:Harris
</textarea>
I am trying to use the Google API time zones, and first you must geocode the address to get the lat/long for time zone. How would I go about doing this from a value in a textarea? 2 steps,
- convert textarea value to geocode example
https://maps.googleapis./maps/api/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY
- then use this lat/long to get the timezone example
https://maps.googleapis./maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=API_KEY?
<textarea id="phyaddr">
123 Address
Suite 1200
Houston TX 77008
USA
County:Harris
</textarea>
Share
Improve this question
edited Feb 27, 2018 at 13:08
Vivek
3321 silver badge13 bronze badges
asked Sep 22, 2014 at 17:04
triplethreat77triplethreat77
1,2968 gold badges35 silver badges70 bronze badges
4
- 2 is that a question? It looks like you just described how to do it... if your looking for someone here to code it for you , they won't . write the code yourself , then paste it here with specific parts you're having problems with – Scott Selby Commented Sep 22, 2014 at 17:06
- I need to know how to get the textarea value to url form with plus and mas, then grab the lat/long from the geocode output. – triplethreat77 Commented Sep 22, 2014 at 17:10
- added a new answer , I think you are confused over the different API's that Google offers – Scott Selby Commented Sep 22, 2014 at 17:45
- You are correct in the calls you have to make. But you should read the documentation for The Google Geocoding API and The Google Time Zone API. Also, search around a bit. There are plenty of questions about each of these. If you get stuck, show the code you tried when asking. So far, all you've done is made a request for someone to write code for you - which is not what StackOverflow is for. – Matt Johnson-Pint Commented Sep 22, 2014 at 22:59
1 Answer
Reset to default 0The 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();
本文标签: javascriptHow to get timezone from address value with Google APIStack Overflow
版权声明:本文标题:javascript - How to get timezone from address value with Google API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745033714a2638655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论