Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-19-2013, 11:45 AM   PM User | #1
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
Question Help on finding world weather based on the visitors longitude and latitude?

Hello,

Anywhere in the world the visitor is on my website, if they give my website permissions, the website will know their longitude and latitude. From this information, I need to find out their:
  • Weather - For example: Sunny, Showers
  • Temperature:
  • > Current - Example: 10°C
  • > High - Example: 20°C
  • > Low - Example: 5°C
  • Humidity - Example: 83%
  • Visibility - Example: Good
  • Pressure (Millibars) - Example: 996
  • Wind Direction - Example: ENE
  • Wind Speed mph - Example: 2mph

Basically, I need as much information as I can get to be able to show on my own website as you see on: http://www.bbc.co.uk/weather/2643123

The BBC does offer an RSS Feed: http://open.live.bbc.co.uk/weather/f...ayforecast.rss

However I need one which you can use with the visitors longitude and latitude for anywhere in the world and I am not sure if there are any services which provide this, whether I need to include multiple for the different countries or whatnot and could really do with some help.

Thank you for any help and/or advice in answering my question.

Best Regards,
Tim
MrTIMarshall is offline   Reply With Quote
Old 03-19-2013, 01:29 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
How far are you with your script?

Are you at a point where you can use the Google Map V3 locator to provide you with a city and country? Can you demo that for us on a web page?

Once you can get the city and country of a user, it will be easy (easier) to get the weather info.
mlseim is offline   Reply With Quote
Old 03-19-2013, 06:45 PM   PM User | #3
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
I am currently setting up a HTML5 Geolocation API on my website. There is currently no live demo which I can yet provide.
MrTIMarshall is offline   Reply With Quote
Old 03-20-2013, 02:19 AM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Once you can get a country and city, you go to weatherunderground and register for an API key. The key is free to use for up to 500 lookups per day. More than that, you'll need to pay a monthly fee.

A PHP script can use CURL to grab the XML file for your designated city.

Example, when I access this XML file, I get the results shown below:

http://api.wunderground.com/api/mykeygoeshere/conditions/q/UK/Manchester.xml

So with Google Maps locator, you'll need to know the country name ( UK ) and the city ( Manchester ).
Examples in the U.S. would be: /MN/Minneapolis.xml (state/city).


XML Results:
PHP Code:

<response>
<
version>0.1</version>
<
termsofService>http://www.wunderground.com/weather/api/d/terms.html</termsofService>
<features>
<
feature>conditions</feature>
</
features>
<
current_observation>
<
image>
<
url>http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png</url>
<title>Weather Underground</title>
<
link>http://www.wunderground.com</link>
</image>
<
display_location>
<
full>ManchesterUnited Kingdom</full>
<
city>Manchester</city>
<
state/>
<
state_name>United Kingdom</state_name>
<
country>UK</country>
<
country_iso3166>GB</country_iso3166>
<
zip>00000</zip>
<
latitude>53.34999847</latitude>
<
longitude>-2.26999998</longitude>
<
elevation>78.00000000</elevation>
</
display_location>
<
observation_location>
<
full>Manchester, </full>
<
city>Manchester</city>
<
state/>
<
country>UK</country>
<
country_iso3166>GB</country_iso3166>
<
latitude>53.34999847</latitude>
<
longitude>-2.26999998</longitude>
<
elevation>256 ft</elevation>
</
observation_location>
<
estimated>
        </
estimated>
        <
station_id>EGCC</station_id>
        <
observation_time>Last Updated on March 2012:50 AM GMT</observation_time>
        <
observation_time_rfc822>Wed20 Mar 2013 00:50:00 +0000</observation_time_rfc822>
        <
observation_epoch>1363740600</observation_epoch>
        <
local_time_rfc822>Wed20 Mar 2013 01:08:22 +0000</local_time_rfc822>
        <
local_epoch>1363741702</local_epoch>
        <
local_tz_short>GMT</local_tz_short>
        <
local_tz_long>Europe/London</local_tz_long>
        <
local_tz_offset>+0000</local_tz_offset>
        <
weather>Mostly Cloudy</weather><temperature_string>37 F (3 C)</temperature_string>
        <
temp_f>37</temp_f>
        <
temp_c>3</temp_c>
        <
relative_humidity>81%</relative_humidity>
        <
wind_string>From the East at 8 MPH</wind_string>
        <
wind_dir>East</wind_dir>
        <
wind_degrees>80</wind_degrees>
        <
wind_mph>8</wind_mph>
        <
wind_gust_mph>0</wind_gust_mph>
        <
wind_kph>13</wind_kph>
        <
wind_gust_kph>0</wind_gust_kph>
        <
pressure_mb>1001</pressure_mb>
        <
pressure_in>29.56</pressure_in>
        <
pressure_trend>0</pressure_trend>
        <
dewpoint_string>32 F (0 C)</dewpoint_string>
        <
dewpoint_f>32</dewpoint_f>
        <
dewpoint_c>0</dewpoint_c>
        <
heat_index_string>NA</heat_index_string>
        <
heat_index_f>NA</heat_index_f>
        <
heat_index_c>NA</heat_index_c><
        
windchill_string>31 F (0 C)</windchill_string>
        <
windchill_f>31</windchill_f>
        <
windchill_c>0</windchill_c>
        <
feelslike_string>31 F (0 C)</feelslike_string>
        <
feelslike_f>31</feelslike_f>
        <
feelslike_c>0</feelslike_c>
        <
visibility_mi>6.2</visibility_mi>
        <
visibility_km>10.0</visibility_km>
        <
solarradiation/><UV>0</UV>
        <
precip_1hr_string>-9999.00 in (-9999.00 mm)</precip_1hr_string>
        <
precip_1hr_in>-9999.00</precip_1hr_in>
        <
precip_1hr_metric>-9999.00</precip_1hr_metric>
        <
precip_today_string>0.00 in (0.0 mm)</precip_today_string>
        <
precip_today_in>0.00</precip_today_in>
        <
precip_today_metric>0.0</precip_today_metric>
        <
icon>mostlycloudy</icon>
        <
icon_url>http://icons-ak.wxug.com/i/c/k/nt_mostlycloudy.gif</icon_url>
        
<forecast_url>http://www.wunderground.com/global/stations/03334.html</forecast_url>
        
<history_url>http://www.wunderground.com/history/airport/EGCC/2013/3/20/DailyHistory.html</history_url>
        
<ob_url>http://www.wunderground.com/cgi-bin/findweather/getForecast?query=53.34999847,-2.26999998</ob_url>
        
</current_observation>
        </
response
PHP can parse that XML file and dynamically generate any web page you wish. There are many different API reports and data collections to access.

Even if you have to pay a monthly fee, look at how much data you can get.

See this for more info:
http://www.wunderground.com/weather/api/d/docs


.

Last edited by mlseim; 03-20-2013 at 02:23 AM..
mlseim is offline   Reply With Quote
Old 03-20-2013, 09:17 AM   PM User | #5
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
check this out.
it says it's depracted, but i see that text since long long time and they don't take it offline, so i guess you can use it for now
http://api.wunderground.com/auto/wui...,-122.39418793
it will give you nearest stations to use with mlseim's example
patryk is offline   Reply With Quote
Old 03-20-2013, 12:32 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
patryk ...

I suppose you could use that 'old' API to get nearby location information based on GPS coordinates. It would take a bit more scripting and still the other API would need to be used for the actual weather reports. A person would have to experiment and see if the Google map locator even gets you close to where you really are.

When I use the Google locator, it sometimes gets me in the Twin Cities (Minnesota) where I'm located. Other times it puts me closer to South Dakota. Even though the location is off by only 300 miles, that makes a difference in the weather. That Google locator thing is just not reliable (in my opinion).

Most people know what city and state (or country) they are currently at. One might think that it would be easiest to just enter that in. We don't know the original intent of the OP.
mlseim is offline   Reply With Quote
Old 03-20-2013, 06:18 PM   PM User | #7
patryk
Regular Coder

 
patryk's Avatar
 
Join Date: Oct 2012
Location: /dev/couch
Posts: 395
Thanks: 2
Thanked 64 Times in 64 Posts
patryk is on a distinguished road
i actually found one free api with coordinates based lookup
http://www.myweather2.com/developer/...b-d771a92b9dbf
patryk is offline   Reply With Quote
Old 03-20-2013, 06:29 PM   PM User | #8
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
That could be an interesting one to try. I've never used that one before.
mlseim is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:56 AM.


Advertisement
Log in to turn off these ads.