javascript - Convert address field to coordinates - Stack Overflow

I have a field called ADDRESS on my webpage. I also have a field called COORDINATES on my webpage. Can

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348857a4427098.html

相关推荐

  • javascript - Convert address field to coordinates - Stack Overflow

    I have a field called ADDRESS on my webpage. I also have a field called COORDINATES on my webpage. Can

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信