How to get the address from Google's Api coordinates JS

I created a map on my website. User can add multiple markers. And on the other page I created a call to these markers. Here is a string:

string '[{"lat":"40.7181193798","lng":"-84.4847297668","label":"A"},{"lat":"40.9530752681","lng":"-83.9779055864","label":"A"}]'

How to make it display only the address. Like "USA,NY,gikalo street ..." And created a link to Google maps with this location. Thank you in advance

Upvotes: 0

Views: 639

Answers (2)

khush1
khush1

Reputation: 11

You will need API key inorder to make the Google Map API request everytime.

Upvotes: 1

Negi Rox
Negi Rox

Reputation: 3922

var z='[{"lat":"40.7181193798","lng":"-84.4847297668","label":"A"},{"lat":"40.9530752681","lng":"-83.9779055864","label":"A"}]'

var JSONArray=JSON.parse(z);
var lat=JSONArray[0].lat;//For first obj
var long=JSONArray[0].long;//For first obj

var dataURL="http://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+long+"&sensor=true";

You can fetch your data by using this url Just you need to parse your JSON in response you wil get appropriate result.

Upvotes: 2

Related Questions