最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Convert address field to coordinates - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 6

Try 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>
发布评论

评论列表(0)

  1. 暂无评论