#1
  1. I love your chinese eyes :*
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jan 2006
    Location
    Her heart... she claims!
    Posts
    1,668
    Rep Power
    1049

    Find weather based on ip address of visitor


    Hi

    is there anyway to find the ip address of the visitor and then find the weather of his city on the fly? I am expert with PHP-cURL so can grab weather from a third party site like yahoo weathers but not sure how to do both tass in one go on the fly.. does anyone know if there is any such ready made script available?

    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2006
    Posts
    63
    Rep Power
    21
    Hi,

    You could use GeoIP to get a city location from IP. Then you could use the Yahoo Weather Web Service or similar to get the actual weather. However, how often is it that someone actually lives in the same town/city as their ISP's server? Going by that, I'd get weather forecasts for a town over 400 miles away.

    Hope this helps,

    Fish
  4. #3
  5. Web Developer/Musician
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Nov 2004
    Location
    Tennessee Mountains
    Posts
    2,411
    Rep Power
    1032
    There are other problems with using those services. GeoIP for instance says i live in France. The services that are accurate, are either expensive commercial web services, or have hit restrictions for personal sites and pretty hefty commercial rates, for anything above that.

    it's not like the location data itself costs a lot, most of those services combine whois data with geo data from the US census Tigerline database (which is free), but the work needed to get usable data out of that set, is considerable, and considering the demand, everyone gets to pay a premium for the pleasure of using it.
  6. #4
  7. I love your chinese eyes :*
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jan 2006
    Location
    Her heart... she claims!
    Posts
    1,668
    Rep Power
    1049
    it also requires apache mod geoip which is only available , in most cases, on dedicated servers and not shared hosting....
  8. #5
  9. Web Developer/Musician
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Nov 2004
    Location
    Tennessee Mountains
    Posts
    2,411
    Rep Power
    1032
    There are a couple of classes on PHP classes that do GeoIP or use other services, but the accuracy, is just too poor.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jan 2005
    Posts
    1,586
    Rep Power
    275
    I have something that might work for you, but that depends on where most of your visitors are from. The reason why, is because many places don't have weather data for their location. But for area's like (US, Canada, Mexico, Western Europe) I can probably help you. It's not an exact science but it's as close as you will get for something that is free. The IP database it uses is current for this month, this a pay for database, but you can use the free one that maxmind has GEOIP_LITE_CITY.

    I can't upload it, because the whole thing is 23MB, which includes API Developer access to Weather.com, XML parser, May 5, 2007 Weather.com Location Database in Mysql format, April 12, 2007 World ICO/METAR Location Database in Mysql format, and the images, scripts, language files and caching system to fetch and maintain your forecast caching system. All you have to do is create templates that will display what you want the forecast to show.

    So if you want it, send me a PM and I'll email it to you!

    My notebook example, not all the forecast locations are included in this example, there are 149,186 locations. I only loaded the weather.com database which has only 43,243 locations! So the example is missing over 100,000 locations, sorry, to lazy to load them all.

    Example


    This explains the forecast arrays...

    Code:
    // current
    
    region =>  FORECAST REGION
    country => COUNTRY NAME
    state => STATE NAME [U.S.A only, other => ++67++ -> -na-]
    place => WEATHER LOCATION NAME
    now => HOURS FROM [GMT]
    sunr => SUN RISE LOCATION LOCAL TIME [timesamp]
    suns => SUN SET LOCATION LOCAL TIME [timesamp]
    last => LAST TIME UPDATED [timestamp]
    f_temp => CURRENT TEMPERATURE [farenheit, language variable]
    c_temp => CURRENT TEMPERATURE [celsius, language variable]
    f_like => CURRENT FEELS LIKE TEMPERATURE [farenheit, language variable]
    c_like => CURRENT FEELS LIKE TEMPERATURE [celsius, language variable]
    icon => CURRENT CONDITION [icon]
    cond => CURRENT CONDITION TEXT [language variable]
    f_baro => CURRENT BAROMETER [standard, language variable]
    c_baro => CURRENT BAROMETER [metric, language variable]
    cbi => BAROMETER MOVEMENT [icon]
    cbt => BAROMETER MOVEMENT [language variable]
    f_spd => CURRENT WIND SPEED [standard, language variable]
    c_spd => CURRENT WIND SPEED [metric, language variable]
    direct => CURRENT WIND DIRECTION [language variable]
    humid => CURRENT HUMIDITY [language variable]
    f_vis => CURRENT VISIBILITY [standard, language variable]
    c_vis => CURRENT VISIBILITY [metric, language variable]
    ultra => CURRENT ULTRAVIOLET [language variable]
    f_dew => CURRENT DEW POINT [standard, language variable]
    c_dew => CURRENT DEW POINT [metric, language variable]
    moon_icon => NIGHT TIME MOON [icon]
    moon_text => NIGHT TIME MOON TEXT [language variable]
    
    
    // extended
    
    0 => DAY OF WEEK [language variable]
    1 => DATE / LOCATION LOCAL TIME [timestamp]
    2 => SUNRISE LOCAL TIME [timestamp]
    3 => SUNSET LOCAL TIME [timestamp]
    4 => TEMPERATURE / HIGH [farenheit, language variable]
    5 => TEMPERATURE / HIGH [celsius, language variable]
    6 => TEMPERATURE / LOW [farenheit, language variable]
    7 => TEMPERATURE / LOW [celsius, language variable]
    8 => DAY TIME CONDITION [icon]
    9 => DAY TIME CONDITION [language variable]
    10 => DAY TIME WIND SPEED [standard, language variable]
    11 => DAY TIME WIND SPEED [metric, language variable]
    12 => DAY TIME WIND DIRECTION [language variable]
    13 => DAY TIME PRECIPITATION [language variable]
    14 => DAY TIME HUMIDITY [language variable]
    15 => NIGHT TIME CONDITION [icon]
    16 => NIGHT TIME CONDITION [language variable]
    17 => NIGHT TIME WIND SPEED [standard, language variable]
    18 => NIGHT TIME WIND SPEED [metric, language variable]
    19 => NIGHT TIME WIND DIRECTION [language variable]
    20 => NIGHT TIME PRECIPITATION [language variable]
    21 => NIGHT TIME HUMIDITY [language variable]
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Weather


    I think it's just a matter of finding the sites that have the information available. Although the ip address and city location are not accurate sometimes, it's still the best route to take if you ask me. I grab the ip address, use that ip address to find their location then take that location and find the weather for that location all in one php script. The only problem with the script is if any of the sites that are being scraped changes anything then the application breaks and needs to be updated. A working model is located at jinises.com
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    11
    Rep Power
    0
    This was a 2007 post, but why mess around with trying to re-create the wheel when the weather channel has already created a complete API that they will give to you for free? The site states that the API includes "Complete Geo-Location Service".
    http://www.wunderground.com/weather/api/?ref=twc

IMN logo majestic logo threadwatch logo seochat tools logo