Since GPS is working know I like to share some information about how to do this. I made a weather app that uses gps and obtains weather from local weather stations. I use rapid xml and c++ for this. Some things to know about this is that you need to know how to parse a website to gather information about the weather.
Some things you need to know is how to get the distance from gps location to closest station. This is in c++.
// this get the closest weather station;
float xmleng::getdistlatlong(float lat1, float long1, float lat2, float long2)
{
float rad = 6372.797;
lat1 = lat1*pi / 180;
lat2 = lat2*pi / 180;
long1 = long1*pi / 180;
long2 = long2*pi / 180;
double dlat = (lat2 - lat1);
double dlng = (long2 - long1);
//float a=agk::Sin(dlat/2)*agk::Sin(dlat/2)+agk::Sin(dlong/2)*agk::Sin(dlong/2)*agk::Cos(lat1)*agk::Sin(lat2);
double a = sin(dlat / 2)*sin(dlat / 2) + sin(dlng / 2)*sin(dlng / 2)*cos(lat1)*cos(lat2);
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
double d = rad*c;
return d;
}
This code gathers the information about the closest point to what is calculated on earth.
Know its time to get the weather of the closest weather station. to do this we have to define the biggest distance that would occur between a weather station and a lat long cord. I made a weatherstuff2.txt which includes all the lats and longs of all the weather stations for the usa. It might actually include more weather stations then that because I got it off the government website w1.weather.gov.
string xmleng::openfile()
{
bigdist = 10000;
int id = agk::OpenToRead("media/weatherstuff2.txt");
while (!agk::FileEOF(id))
{
cords.stationid = agk::ReadString(id);
cords.lat = agk::ReadFloat(id);
cords.longi = agk::ReadFloat(id);
cordslist.push_back(cords);
}
agk::CloseFile(id);
float getx = 42.87;
float gety = -112.44;
if (agk::GetGPSSensorExists() == 1)
{
agk::StartGPSTracking();
if (agk::GetRawGPSLatitude() != 0)
{
getx = agk::GetRawGPSLatitude();
}
if (agk::GetRawGPSLongitude() != 0)
{
gety = agk::GetRawGPSLongitude();
}
agk::StopGPSTracking();
}
for (int i = 0; i<cordslist.size(); i++)
{
//shortestdist=cordslist[i].lat-43.6137;
float latstr = cordslist[i].lat;
float longstr = cordslist[i].longi;
if (longstr != 0 && latstr != 0 && cordslist[i].stationid != "")
{
shortestdist = getdistlatlong(getx, gety, latstr, longstr);
}
//agk::GetSpriteDistance(
if (shortestdist<abs(bigdist))
{
bigdist = shortestdist;
point = i;
}
}
int connect = agk::CreateHTTPConnection();
agk::SetHTTPHost(connect, "w1.weather.gov", 0);
string xmlcurcond = "xml/current_obs/";
xmlcurcond = xmlcurcond + cordslist[point].stationid.c_str();
xmlcurcond = xmlcurcond + ".xml";
weather = agk::SendHTTPRequest(connect, xmlcurcond.c_str());
return weather;
}
This is pretty much how I did it and it works pretty well if you have gps on your mobile device.
Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.