eigan / yr-php-library

Small php library for the norwegian weather service Yr.
18 stars 4 forks source link

Location by Lat/Lon #9

Open robwent opened 8 years ago

robwent commented 8 years ago

This is more of a feature request than an issue but I'm not sure if it's possible.

I want to get forecasts by coordinates rather than by a page url on the yr.no website. This is possible though the api by specifying lat, lon and an optional meters above sea level.

http://api.yr.no/weatherapi/locationforecast/1.9/documentation

I've looked through the code and it seems the class isn't using the api directly, it's using the standard site urls which return an xml eg: http://www.yr.no/place/United_Kingdom/England/East_Leake/forecast_hour_by_hour.xml

So I guess the questin really is, is it possible to add this or would the class basically need rewriting?

eigan commented 8 years ago

Sorry, but I'am no longer investing time in this project. You should consider using Forecast.io (they use same source as this library for norwegian weather).

Here is a github search for forecast io php wrappers: https://github.com/search?l=PHP&o=desc&q=forecast+io&s=stars&type=Repositories&utf8=%E2%9C%93

I might add this lat/long feature you are requesting at a later time if I come back to this project. Looks like the api you are linking to might work with the existing code.

robwent commented 8 years ago

That looks interesting, thanks. I didn't realise there were any other api's for the same data.

Feel free to close this.

JanPetterMG commented 8 years ago

Another possible solution: If you use the createFromXML($periodic_file_content, $hourly_file_content), all you need is a simple script converting these cordinates to Yr.no API location names, and then download/provide the XML files yourself.

I have a project, translating coordinates to location names using Google Maps API, and then searching Yr.no Astro API for data (sun rise/set moon up/down and moon-phase). I know the API isn't using the same input parameters, but I think what you are asking for is possible, without writing too much code.

robwent commented 8 years ago

What's the astro api? I don't see any mention of that on the site.

I might fork this class and adapt it to use the api.

I will be using geocoding in the application to get the coordinates of a user typed location, it seems a bit long winded to then convert the coordinates back to another location to get the data when they already provide data by coordinates. I also want to use the height parameter to get multiple forecasts for a location.

eigan commented 8 years ago

I didn't realise there were any other api's for the same data.

Their sources is listed here: http://forecast.io/raw/

What's the astro api? I don't see any mention of that on the site.

As a side note on astro api. I have had great experience with http://rhodesmill.org/pyephem/.

Also, there is this: http://php.net/manual/en/function.date-sunset.php. See this comment for more advance usage of these methods: http://php.net/manual/en/function.date-sunrise.php#47839

robwent commented 8 years ago

Wow, this is all great stuff, thanks. I would never have thought php would have native functions for sunset/sunrise.

ghost commented 6 years ago

@eigan This function would solve a lot of issues with my manual extraction of data from YR's API. I would happily use your function instead! What's the status of your interest in adding latitude and longitude support?

eigan commented 6 years ago

@edgren As far as I know YR doesn't support api requests containing lat/lng. This means that we would need to use another service to find the county and city which can be used with the API request into YR. I feel like this kind of logic is not something that fits this project.

I would instead recommend to use a different weather api which supports lat/lng, like https://darksky.net/dev/docs

robwent commented 6 years ago

You can get a forecast by lat/lng using the Locationforecast endpoint

https://api.met.no/weatherapi/locationforecast/1.9/documentation

eg: http://api.yr.no/weatherapi/locationforecast/1.9/?lat=52.954783&lon=-1.158109

eigan commented 6 years ago

Huh, thanks. Might not be too difficult to add support for this then.

On Tue., 24 Apr. 2018, 15:34 Robert Went, notifications@github.com wrote:

You can get a forecast by lat/lng using the Locationforecast endpoint

https://api.met.no/weatherapi/locationforecast/1.9/documentation

eg: http://api.yr.no/weatherapi/locationforecast/1.9/?lat=52.954783&lon=-1.158109

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/eigan/yr-php-library/issues/9#issuecomment-383932301, or mute the thread https://github.com/notifications/unsubscribe-auth/AACjPfgM_WLLyRpjrkn8rcy4m2-XHF10ks5tryntgaJpZM4HCMMV .

eigan commented 6 years ago

I see that you actually mentioned this earlier. Must have forgotten it. My bad

robwent commented 6 years ago

The one thing it doesn't seem to give you in the response is any kind of location information like the Country/City though.

ghost commented 6 years ago

So, you will add support for this after all, @eigan?

eigan commented 6 years ago

Just looked at the API result and there is some missing data (and some more data) that would make this library a bit inconsistent (some data would be null when created with latlng).

I will take a look at it later, but seems like a better approach would be to create a new metno-php wrapper. They have lots for API endpoints for even more data. I have not checked if any library like that exists yet.

eigan commented 6 years ago

Did some more research. I would prefer to move this logic out into a different project. Its something I would like to do but I am really busy at work right now so not going to happen anytime soon.

I will leave this issue open. Please do recommend other (free) projects which supports this feature.