Comments

Vivek Panicker created an issue. See original summary.

vivek panicker’s picture

Issue summary: View changes
jhodgdon’s picture

Title: Map url redirection » Update URLs for Google Maps
Category: Support request » Task
Issue tags: -redirection issue

I think that is a good idea. At some point between when this module was first created and now, Google changed its map URLs. We should definitely update the module in both 8.x and 7.x.

As a note, if your site has a custom theme you can fix this yourself for your site by putting the html.twig file into your theme and editing it there.

vivek panicker’s picture

Hi jhodgdon,

Thank you for looking into it and for giving the suggestion.

But the url query parameters have also changed. For that, the template variable generation logic also has to be changed.
I am finding it difficult to figure out the logic to do so.

It would be great if someone could help me out here.

jhodgdon’s picture

It would help if you could put the full URLs into the issue summary or a comment (the original and the redirect) and maybe we could figure out what is happening).

Also keep in mind that Google often puts a lot of extra stuff into its URLs that are not necessary.

Also... These URLs were originally derived from going to Google Maps, finding an address, clicking on the Embed link, and figuring out what the URL was. We can probably start over and do that again, to figure out where in the URL the language and address should go.

vivek panicker’s picture

Hi jhodgdon,
I shall myself put some effort into finding out if it is possible to come up with a solution for this problem.

The following is the redirect that is happening:

Original
https://maps.google.com/maps?hl=en&q=IN%2C+West+Bengal%2C+Kolkata%2C+700071%2C+Queens+Way%2C%2C+Maidan%2C+Victoria+Memorial+Hall&t=m&z=15&output=embed

Redirect
https://www.google.com/maps/embed?origin=mfe&pb=!1m4!2m1!1sIN,+West+Bengal,+Kolkata,+700071,+Queens+Way,,+Maidan,+Victoria+Memorial+Hall!5e0!6i15!3m1!1sen!5m1!1sen

jhodgdon’s picture

Thanks! So it looks like the address part is staying the same, encoded as IN%2C+West+Bengal%2C+Kolkata%2C+700071%2C+Queens+Way%2C%2C+Maidan%2C+Victoria+Memorial+Hall.
We'd probably need to experiment with the other map parameters to figure them out. ... In the original, we have hl=en , t=m , z=15, which are the language (en), zoom level (15), and map type (m). In the redirect, I see 6i15 which could be the zoom level, and 1sen which could be the language? Hard to say for sure.

So my suggestion would be to put some addresses into Google Maps and click the Embed button, trying with some different zoom levels and map types, to see what the parameters would be. Check the settings for this module to see what other things we'd need to vary to cover all the settings.

vivek panicker’s picture

Thanks for the help!

There are no online resources as such available from Google to help us out here. But I found some blogs which helped me to decode the URL string.

So there is some sort of hierarchy here, but the hierarchy shown in the blogs is different from the hierarchy I am able to construct for my URL string.

!1m4
  !2m1
    !1sIN,+West+Bengal,+Kolkata,+700071,+Queens+Way,,+Maidan,+Victoria+Memorial+Hall
  !5e0
  !6i15
!3m1
  !1sen
!5m1
  !1sen

What I am planning to do is to keep hierarchy same as the one I have, and try to generate it dynamically.
The only change I feel I have to make apart from in the template file, is for the map type value generation. There now seems to be only 2 types of map:

  1. map(default) -> value - 0 (making the code 5e0)
  2. satellite -> value - 1(making the code 5e1)

Apart from this as pointed out by you, 1sen does stand for the langcode and 6i15 does stand for the zoom level.

I'll generate and provide the patch for it. I'll need someone to test the static map part as I am not using it.

vivek panicker’s picture

Status: Active » Needs review
StatusFileSize
new6.71 KB

This patch should fix the issue for dynamic map and link of larger map.
But this does not take into account static maps, as I do not have the API key.

vivek panicker’s picture

Assigned: Unassigned » vivek panicker
Status: Needs review » Needs work
jhodgdon’s picture

That patch is getting a "failed to apply" error...

vivek panicker’s picture

Yes, I saw that too.

I have generated a fresh patch and have uploaded it.

vivek panicker’s picture

Uploading this patch after fixing coding standards issue.

vivek panicker’s picture

jhodgdon’s picture

Status: Needs work » Needs review

When you upload a patch, please just set the issue status to Needs Review, which will automatically launch the correct test. You should not need to manually add tests. Thanks!

jhodgdon’s picture

Status: Needs review » Needs work

I took a quick look at the latest patch. I actually think it would be better to leave the settings form as it is, and instead when you are sending data to the theme layer, translate the map types to fit the current Google URLs. That will make existing sites still work. The way you have done it, if someone updates the module to the new version, their existing configuration for the field formatter will no longer work. So you would need to have an update hook that would go through and update everyone's configuration, which is not in the patch.

Updating the variables sent to the theme is also a problem, because if someone is using a customized theme template file, it will no longer be getting the same data.

So... I'm setting the patch to needs work. We need a patch that will make it so that sites that already exist (with existing configuration and perhaps customized theme templates) will still work if they update to the new version. This patch will not work.

vivek panicker’s picture

Hi jhodgdon,

Yes, I too realized the issue with updating the values in the settings form and the necessity for an update hook. I just wanted to share the code as fast as possible so that someone could review and it tell me if I was heading in the right direction.

So, thank you for the review and the explanation!

I did not though think about translating values when sent to the theme layer. But as you pointed out, that people with customized theme template would not be able to make use of the updated settings values.

I shall put some thought into it and see if I can come up with a solution.

jhodgdon’s picture

I think the solution is probably to leave the configuration and the theme variables the same, and have the logic of translating the old map type to the new map type be done in the theme template. That way, old templates that are outputting the old URLs with the old values will still work, old configuration will still work (without an update hook), and the new template will still be able to output the new URL.

vivek panicker’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB

Yeah... I guess that would be good. It would help maintain compatibility.
Also the approach it has made the code much simpler.

I am uploading another patch with changes just in the template in URL value and map_type value.

vivek panicker’s picture

The patch is failing for higher Drupal versions as some deprecated methods are being called.
So I tested against Drupal 8.6 and the patch works.

I guess the tests need to be updated as well.

jhodgdon’s picture

Yes, we need to fix the deprecations. See #3088320: Make sure Simple Google Maps is fully Drupal 9 compatible for that.

The patch looks like the right approach. I haven't tested it yet, and I think it needs manual testing. Thanks very much for all your work!

One question: I think when I first made this module, I experimented with taking bits out of the URL so that I had a minimal URL to work with. You might try that with the new URL. For instance, maybe it doesn't need the language code twice: !3m1!1s{{ langcode }}!5m1!1s{{ langcode }}? I am not sure, it would require some experiments to see if it still works without some of the little bits in the URL that we don't really know what they are.

vivek panicker’s picture

StatusFileSize
new1.46 KB

I have tried out a shortened URL and created a patch for it.
Uploading it now....
I don't think it can be any shorter than this.

One thing I would like to again point out that this patch or the previous one does not fix the URL for static maps as I do not have any API key to test it.

Glad to help!

jhodgdon’s picture

Thanks for that testing! But that may be too short -- it looks like that patch doesn't output the language code?

vivek panicker’s picture

Thanks for pointing it out. Had removed that code in a hurry.
I have created a new patch with the langcode parameter that is required.

jhodgdon’s picture

That looks better! We should do a bit of manual testing with various options to verify that the field formatter settings still work for zoom, language, map type, and of course the address.

Meanwhile, you can of course put the new template into your site's theme and benefit from all of your hard work on this patch, which is much appreciated!

jhodgdon’s picture

Issue tags: +Needs manual testing
vivek panicker’s picture

Thanks for the approval :)
I have downloaded the dev version of the module in my project and applied the patch to it. Worked fine.

I have also done some testing and things look fine to me.
Hope that the it works fine for other testers as well!

baluertl’s picture

Iʼm not sure whether I understood the purpose of this module correctly, but as far as I see, Google Maps GUI now uses exclusively &mid= (named after probably "Map ID"?) parameter is its URLs. I tried many ways but did not manage to get a URL of my map similar to these exclamation mark-separated &pb=!1m4!2m1!1s… style which weʼre compositing.

Maybe Google just changed the embedding options since the last comment here and we have to accommodate with their new rules. When I require the embed code of my map I get the following markup offered:

<iframe src="https://www.google.com/maps/d/embed?mid=1GGjVwVq2A4YFsCbQ0Al1wzGBfpRRnVtG" width="640" height="480"></iframe>

Such sophisticated options this field formatter was used to offer are nowhere mentioned by Google on the GUI anymore. Correct me if Iʼm wrong, maybe thereʼs another "Google Map" service in the overwhelming Alphabet-universe I just missed?

jhodgdon’s picture

The original embed code for this module was derived from reverse-engineering an embed generated by searching on the Google Maps web site for an address, clicking on Share, and looking at the embed code. It was not based on a published API. The no-API-key embed may fail to work in the future (or even now?) if they are publishing the embed with a map ID and keeping track of the options behind the scenes.

The URL link was also based on reverse-engineering links from the popup share button.

The static map option in this module does used a published API, and requires a Google Maps API key and payment to Google.

bserem’s picture

Status: Needs review » Reviewed & tested by the community

Today our production pages with simple_gmap stopped working and displayed a sameorigin error:

Refused to display 'https://maps.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

The patch in #24 solves the issue nicely and quickly.

I'd put this to RTBC since it seems that without it the module won't work properly anymore.

designate’s picture

What would be the #24 patch for Drupal 7 version of this module?

darrell_ulm’s picture

Adding support, agree that the patch in #24 applied works and solves the issue.

cbwiedel’s picture

Confirming patch in #24 solved my issue too

hunterbuchanan’s picture

Version: 8.x-1.4 » 3.0.0
Category: Task » Bug report
Priority: Normal » Major
Issue tags: -Needs manual testing

Agreed, just tested patch #24, it solves the problem for us as well.

This URL issue used to just be a minor annoyance, but now that Google has made changes on their end, the module is entirely broken without this fix. Making adjustments to the issue to reflect the urgency here.

Patch #24 should be committed to dev right away, and a new release including this change should be tagged. It looks like the current dev branch is 8.x-1.x, while the release versions are up to 3.0.0, but I'm not sure if that has to change in order to move this forward.

Anonymous’s picture

We tested the patch on a site using Drupal 9 and it fixes the broken maps for the embedded dynamic map.
Waiting for a dev or release version before we update all our sites.

cboyden’s picture

Version: 3.0.0 » 8.x-1.4
Category: Bug report » Task
Priority: Major » Normal
StatusFileSize
new1.57 KB

Here's a patch for the 7.x version based on #24.

cboyden’s picture

Version: 8.x-1.4 » 3.0.0
Category: Task » Bug report
Priority: Normal » Major
designate’s picture

Confirmation that patch for Drupal 7 as described in # 36 works and solves the problem!

jhodgdon’s picture

Assigned: vivek panicker » martin107

Hi there! Thanks everyone for reviewing these patches.

I'm sorry but I'm not able to make the commit/release for about a week (away from office). Possibly the module co-maintainer for Drupal 8+ can take care of it before that.

hunterbuchanan’s picture

Thanks for letting us know @jhodgdon! I messaged Martin directly to ask him if he could take care of it soon.

  • jhodgdon committed 11ae094 on 3.0.x
    Issue #3092918 by Vivek Panicker, cboyden, jhodgdon, designate,...

  • jhodgdon committed b42d693 on 7.x-1.x
    Issue #3092918 by Vivek Panicker, cboyden, jhodgdon, designate,...
jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone who participated in this issue by creating and testing patches, as well as discussing the issue and how to fix it! And thanks for your patience. There are now a new 8.x/9.x and 7.x releases available on the project page, with this fix included.

jhodgdon’s picture

Assigned: martin107 » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.