Extract coordinates of an address with the Google Maps API

0

I'm building a map with custom markers taken from a MySQL database

I have the following var in js with different coordinates

var locations = [
        {lat: 41.641581, lng: -4.780962},
        {lat: 41.681581, lng: -4.740961},
        {lat: 41.661481, lng: -4.710061},
      ]

The problem is that in my database the coordinates are not saved, but the complete address, from the following example link you can extract the coordinates of the addresses.

https://maps.googleapis.com/maps/api/geocode/json?address=C/ de las eras 9 - Iscar&key=MI_API_KEY

I would like to know if you can get the coordinates of a direction directly from a script in js without having to go through that link. And if it could not, how do I extract the coordinates of that file?

    
asked by Tefef 14.09.2018 в 10:07
source

1 answer

0

Enter to try the code and put your api key

$.get('https://maps.googleapis.com/maps/api/geocode/json?address=C/%20de%20las%20eras%209%20-%20Iscar&key=TU_API_KEY', 
  function(data) {
    console.log(data.results[0].geometry.location);
  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
answered by 14.09.2018 в 13:03