admin管理员组文章数量:1334133
I have a field called ADDRESS on my webpage. I also have a field called COORDINATES on my webpage. Can someone give me specific JQUERY or JAVASCRIPT code to take the address in ADDRESS and have lattitude and longitude coordinates show up in COORDINATES field.
EXAMPLE
ADDRESS - 1 MetLife Stadium Dr, East Rutherford, NJ 07073
COORDINATES - 40.814209 / -74.073690
Please give a specific example. I know i might need an API key or something. I tried looking at google maps API documentation, but it was a bit confusing. Thank You.
I have a field called ADDRESS on my webpage. I also have a field called COORDINATES on my webpage. Can someone give me specific JQUERY or JAVASCRIPT code to take the address in ADDRESS and have lattitude and longitude coordinates show up in COORDINATES field.
EXAMPLE
ADDRESS - 1 MetLife Stadium Dr, East Rutherford, NJ 07073
COORDINATES - 40.814209 / -74.073690
Please give a specific example. I know i might need an API key or something. I tried looking at google maps API documentation, but it was a bit confusing. Thank You.
Share Improve this question asked Jan 12, 2016 at 5:54 Maria NolorbeMaria Nolorbe 3571 gold badge4 silver badges14 bronze badges 1- 1 This is called reverse geocoding and the google maps geocode API has all the information you need to do this. Finding examples is not hard – charlietfl Commented Jan 12, 2016 at 6:11
1 Answer
Reset to default 6Try this!
<script type="text/javascript" src="http://maps.google./maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
var address = jQuery('#address').val();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
jQuery('#coordinates').val(latitude+', '+longitude);
}
});
</script>
本文标签: javascriptConvert address field to coordinatesStack Overflow
版权声明:本文标题:javascript - Convert address field to coordinates - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742348857a2458076.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论