I want my vistior to enter a city name then I can get the latitude and longitude from that name. I could not figure out how to get them using google map api. I found world weather online api easy, so I have this json response but cannot walk through it.
{ "search_api" : {
"result" : [
{ "areaName" : [ { "value" : "New York" } ],
"country" : [ { "value" : "United States Of America" } ],
"latitude" : "40.710",
"longitude" : "-74.010",
"population" : "8107916",
"region" : [ { "value" : "New York" } ],
"weatherUrl" : [ { "value": "http:\/\/free.worldweatheronline.com\/weather\/United-States-Of-America\/2395340\/New-York\/2478232\/info.aspx" } ]
},
{ "areaName" : [ { "value" : "New York" } ],
"country" : [ { "value" : "United States Of America" } ],
"latitude" : "32.170",
"longitude" : "-95.670",
"population" : "0",
"region" : [ { "value" : "Texas" } ],
"weatherUrl" : [ { "value": "http:\/\/free.worldweatheronline.com\/weather\/United-States-Of-America\/2395340\/New-York\/2516758\/info.aspx" } ]
}
]
}
}
This is what I tried:
$.getJSON(url, function(data) {
var cord = data.search_api.latitude;
alert(cord);
} );
Can anybody help me out with this or give me a better way to get longitude and latitude from a given city name or address?