New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drop Google Maps for Open Street Map #3025
Conversation
@Baiqiang, it would be very interesting to see if it has some visible effect in countries not in love with google ;) |
I'm pretty sure commit 1c8fef0
commit eeb00fe
commit a9d51d0
It seems like a real shame to me to move away from Google's search here, because as you pointed out, it will break competition tabs that display a map (such as https://staging.worldcubeassociation.org/competitions/DallasFortWorth2018#5378-venue). What would be the consequences of sticking with using Google's search for now? Is it also going to be rate limited in the ways that maps are going to be limited? Speaking of competition tabs, I am super freaking pleased that you're able to make changes to all the past competition tabs here. That would not have been nearly as easy if we'd let people input arbitrary html. Great future proofing, @jonatanklosko! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viroulep thanks so much for taking this on!
I'd like to better understand the resizing logic you had to add to get things working. Basically, at a high level, if google maps was able to work without us notifying it whenever it becomes visible, it feels to me like we should be able to get leaflet to do the same thing.
I don't want this investigation to keep this code from getting merged up, but I do think it's worth spending some time trying to understand it. I'm happy to help investigate if you want to point me in the right direction =)
As mentioned already, I think it might be good to make the switch to OSM+leaflet, but keep using google's search to get lat long for locations. That would minimize churn, and we could always look into switching to a different geocoder later.
I just went to https://www.worldcubeassociation.org/competitions/new, and it looks like we're finally getting blocked: So, it's probably more important now to get this change merged up. |
Ah crap, we did end up reaching the limit :(
Yes, and I hope this solution won't reach gmaps limit for the number of queries... |
FYI, according to this page, we can get up to 40 000 geocoding queries per month. Geocoding is not used in many places of the website:
So we should be fine, I hope :p |
7d88377
to
ac6babf
Compare
The tests failures I experienced were quite disturbing at first, the test for the "manage schedule" page was failing because Solutions and workaround I found:
1 would involve us storing our own built version of PhantomJS somewhere. Please let me know if you have any other ideas! Also I've deployed this to staging, so feel free to see how it looks and experiment there! |
@viroulep, things seem to be working ok now that we've enabled billing on our google maps account. Do you think we should drop this PR for now? The only real problem with have with google maps is that it doesn't work in China, but AFAIK, all comps in China use cubingchina, so that's not a big issue. |
It seemed to be a great opportunity for us to move away from Google Maps :p Also, while enabling billing was required for us to use the webservice API, it is not required for our current setup. I acknowledge gmaps has a better geocoding API than Nominatim, so it probably makes sense to keep this no matter what. Also note that we could still bring in leaflet with gmaps provider :p |
Yeah, I'm all for switching to something less restrictive in the future, but I don't know if it's worth focusing on right now. That said, if you're motivated to keep working on this, I'm all for it! Next things I'd like to investigate:
|
ac6babf
to
f3d6e68
Compare
|
||
$('#competitions-map').one('map-shown', function() { | ||
/* Google Map is not properly initialized within a hidden container, that's how we fix it. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfly it seems we had that resizing issue with google maps too, but I have no idea why we didn't have it in the venue picker in the schedule editor...
I just rebased the PR, @Baiqiang I'll deploy this to staging so that you can take a look.
Unfortunately I think leaflet on his own can't do it :s I'm very much open to suggestions, right now I'm out of ideas! |
1c95b68
to
47fd48e
Compare
Sorry for the delay. I finally did some investigation into why Google Maps is behaving differently than Leaflet. I posted the results of my investigation above. Please feel free what to do with that, but otherwise, this PR looks good to me. 🚢 it! |
47fd48e
to
882c48c
Compare
96ce641
to
fab078c
Compare
WcaOnRails/app/javascript/edit-schedule/EditVenue/VenueLocationInputImpl.jsx
Show resolved
Hide resolved
I just deployed it to staging again! |
fab078c
to
3e61865
Compare
Hum I just tried using our google API key to use the google search provider, and got this error:
Let's just drop this... |
3e61865
to
169f127
Compare
- Replace maps in edit schedule - Replace maps in tabs - Replace maps in competitions forms - Replace maps in persons profiles
169f127
to
4dc51ac
Compare
Ok so I've figured out a solution that seems an acceptable tradeoff:
Using OSM+Nominatim lead to a whole lot of broken maps in tabs, so currently I think it's best to avoid nominatim until we find a way to easily fix existing tabs. This PR is currently deployed on staging. @jfly please let me know if I should merge and deploy this! |
(I've edited this wiki entry to mention that we should change the API key restriction after we spin up a new server: https://github.com/thewca/worldcubeassociation.org/wiki/Spinning-up-a-new-server) |
Some extra numbers I fetched from our billing dashboard:
So it seems our current usage of the geocoding API is way below the free tier (200$) offered by google :) |
Hum it's trickier than I thought, since it's the client's IP which is making the geocoding query... |
9b1c5ed
to
a547301
Compare
We want to restrict our Google API key on an IP basis, so we need to make sure the actual query comes from our server (and not from the client). We also want to make sure anyone on the internet can't just use our proxy, so we explicitly check for Rails' CSRF token even if we're just doing a GET query (this way we are sure the query made by the client is legit).
a547301
to
95da715
Compare
I just did so in the last - hopefully clean - commit. It does work with my local development key, and I did a very quick check live by switching the restriction for a couple of minutes and confirming production was blocked and staging was working. |
We actually use a static IP for both staging and our prod server, so it shouldn't actually be necessary to change that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me!
Now that our API token is only used on the backend, I'd actually be ok with creating a brand new, truly secret token and removing the IP restriction entirely. Now that the token is not exposed to the frontend, it's not like people should be able to steal it, and removing the IP restriction will make our lives easier if we ever change server IPs (I know we use a static IP right now, so that's not likely to change, but maybe someday we move off of AWS or (more likely) start spinning up multiple API servers)
BTW, awesome work here. This will be really great to have done. |
95da715
to
f5ce6e9
Compare
Thanks! I've just added a brand new API key to our encrypted data bag, I'll try to deploy this on staging. |
f5ce6e9
to
7cb2838
Compare
7cb2838
to
a434e88
Compare
There is no issue open for this, but if this is merged it would fix #232.
Google Maps will soon (July 16th) charge on a per-map-load basis (see here).
As far as I get it, it would give us just over 28000 map loads monthly.
To be honest I have no idea about how many map loads we do monthly, but I wouldn't be surprise if we were around or over that number.
I think it's a great opportunity to look into free alternatives that exists, and most specifically Open Street Map.
So here is a proof of concept and WIP PR for dropping gmaps for osm, with a list of pros, cons, and some stuff I noticed when testing it.
First of all, places where we use maps in the WCA website, with the features we require:
map()
markup in Markdown (Map + Marker + Search result popup, in iframe).webroot/results/includes/_map.php
, I couldn't find a page where it's actually used, maybe someone better remember what's in there.Support for all this, in the context of OSM, needs several parts:
For the last two there are a bunch of options.
Note: it only provides labels (city names, streets, etc) in their local language, which is both good for locals, and bad for foreigners who don't speak the local language.
For handling search queries I chose to use leaflet-geosearch which has support for various providers.
Obviously they support using gmaps as a search engine, and the two main free alternatives are:
I've deployed it on staging to give you a rough idea of the usability.
Pros
Cons
My overall feeling about dropping gmaps is mostly positive: from a programmer point of view it's definitely very similar (as you can see in the code, it's mostly changing the library includes and moving stuff around). From a user point of view, it can definitely be disappointing to lack details in areas you'd like to see...
However most of the maps offered to the "regular" user are displaying the world as a whole. We actually never display a map zoomed in of a competition venue to the user, but we provide a link with the coordinates (that we can keep pointing to Google Maps).