I already am using a geolocation call from FreeCodeCamp I have a linked OpenWeatherMap API to find weather based on Geolocation I have now added a Google API so I can add not just the City name but also State and Country.
I cannot figure out or find how to use already determined geolocation data to get the info I need from Google GeoCoder API... All I can find on google is to create a new call which is redundant or I am reading wrong or I am not using the correct search terms in google because I am not finding anything...
I am only wanting to pull City, State, Country using Longitude and Latitude coordinates I already have. (I can get City and Country from Open Weather but not State or at least it isn't displaying for me) I am trying to not have to rewrite:
$(document).ready(function (){
var longi;
var lat;
var temp;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
longi = position.coords.longitude;
lat = position.coords.latitude;
// create API with Geolocation
var api = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+longi+"&appid=API_GOES_HERE";
var googGeoloc = "https://maps.googleapis.com/maps/api/js?key=API_GOES_HERE&callback=initMap";
var geocoder = new google.maps.Geocoder;
//$(".location").html(lat + ", " + longi);
$.getJSON(api, function (data) {
//var weatherType = data.weather[0].description;
var ktemp = data.main.temp;
var fTemp = Math.round((ktemp)*(9/5)-459.67); //temp in F
var cTemp = Math.round((fTemp - 32) * (5/9)); //temp in c
var windSpeed = data.wind.speed;
var city = data.name;
$(".location").html(city);
$(".degrees").html("Your Current Temp is: " + fTemp + " Degrees");
});
})
}
});
As you can see from my code I already am grabbing GeoLocation coordinates... I want to use the longitude and latitude info I already have to get either just the State or City, State, Country from the Google API call... I can parse the City and Country from OpenWeatherMap and have on my test page... I just need the State/Province