How to embed Google Map links in posts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tourmeister
    Member
    • Sep 2005
    • 80
    • 3.0.8

    How to embed Google Map links in posts?

    Howdy,

    At one time I had a custom BB Code I got from somewhere that would display Google map links. Then Google went and changed something. It no longer works.

    Can someone show me the Replacement Code needed to make it work with the current Google link? I am NOT a coder, so I need the explicit code, not just a general suggestion ;-)

    It worked like this, [gmap]iframe code[/gmap]

    Here is the replacement code that I currently have,

    Code:
    <script type="text/javascript">
    function checkURL()
      {
          if ((url.indexOf("https://")!=url.lastIndexOf("https://"))||url.lastIndexOf("https://")!=0){return false;}
          if (url.indexOf('&quot')>=0) {return false;}
          if (url.indexOf("https://maps.google")!=0){return false;}
          return true
      }
    
    tot='{param}';
    tot=tot.substr(tot.indexOf("src=&quot;")+10,tot.length);
    url=tot.substr(0,tot.indexOf("&quot;"));
    urlp=url.replace(/;amp;/g,';');
    url=urlp;
    
    if (checkURL())
    {  
        document.write('<center><iframe width="800" height="600" frameborder="1" scrolling="no" marginheight="50" marginwidth="50" src="'+url+'"></iframe></center>');
    }
    else
    {
    document.write("<p><b>Wrong map URL, edit the post to change it.</b></p>Reload the page when finished to check if correct.");
    }
    </script>
    That works with this old link

    [gmap]<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?client=safari&amp;oe=UTF-8&amp;ie=UTF8&amp;gl=us&amp;daddr=Dallas,+TX&amp;saddr=Houston,+TX&amp;panel=1&amp;f=d&amp ;fb=1&amp;dirflg=d&amp;geocode=FcEaxgEdUsdQ-ikBhY1ItLhAhjE7BWXz3gINyg%3BFWwv9AEdPfE6-ilLl0V79xlMhjGPZ0f2pJvsuQ&amp;t=m&amp;vpsrc=0&amp;ll=31.271861,-96.082783&amp;spn=3.022868,1.435487&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?client=safari&amp;oe=UTF-8&amp;ie=UTF8&amp;gl=us&amp;daddr=Dallas,+TX&amp;saddr=Houston,+TX&amp;panel=1&amp;f=d&amp ;fb=1&amp;dirflg=d&amp;geocode=FcEaxgEdUsdQ-ikBhY1ItLhAhjE7BWXz3gINyg%3BFWwv9AEdPfE6-ilLl0V79xlMhjGPZ0f2pJvsuQ&amp;t=m&amp;vpsrc=0&amp;ll=31.271861,-96.082783&amp;spn=3.022868,1.435487&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>[/gmap]


    Any help would be very much appreciated!
    Last edited by Tourmeister; Mon 6 Jun '16, 9:53am.
    Scott Friday
    Two Wheeled Texans
  • Wayne Luke
    vBulletin Technical Support Lead
    • Aug 2000
    • 74154

    #2
    What doesn't work with your code?
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud demonstration site.
    vBulletin 5 API

    Comment

    • Tourmeister
      Member
      • Sep 2005
      • 80
      • 3.0.8

      #3
      Originally posted by Wayne Luke
      What doesn't work with your code?
      Well... that's my question. It simply doesn't embed the map at all. I have no idea what change Google might have made that made it quit working. Like I said, I am not a coder so the javascript stuff means pretty much nothing to me. It's been several years at least since I originally created the custom BB Code with that javascript above and I can't for the life of me remember where I got it from. But it was just a cut/paste thing. I did not create the javascript code myself.

      The following is the embed link from a map today,

      <iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d6991601.953376696!2d-100.0768425!3d31.16893395!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1465 251572704" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>

      I've no idea what all the stuff in the iframe tags does. The only thing I see is that the URL is changed from

      //maps.google.com/

      in the old embed link to

      //www.google.com/maps/

      in the new embed link.

      As for the rest of the stuff... no clue. I don't know how to change the javascript regular expression code to account for that changed URL (or any of the rest of the stuff in the link).
      Scott Friday
      Two Wheeled Texans

      Comment

      • Wayne Luke
        vBulletin Technical Support Lead
        • Aug 2000
        • 74154

        #4
        The code appears to be doing some validation on the URL. Since you're actually using iframes and HTML in your original code, this is a security risk. It would have to be updated to fit the new form of Google's URL. You would have to contact the original author if they are still around.

        Or you can get rid of the HTML and do a code like this:

        Replacement:
        Code:
        <iframe src="https://www.google.com/maps/embed?{param}" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
        Example:
        Code:
        [gmap]pb=!1m14!1m12!1m3!1d6991601.953376696!2d-100.0768425!3d31.16893395!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sen!2sus!4v1465 251572704[/gmap]
        This takes everything after the embed/ and up to the closing " to use as the parameter. This is using your URL provided above in post #3 so you can compare them.

        You can see this here:
        Translations provided by Google.

        Wayne Luke
        The Rabid Badger - a vBulletin Cloud demonstration site.
        vBulletin 5 API

        Comment

        • Tourmeister
          Member
          • Sep 2005
          • 80
          • 3.0.8

          #5
          Howdy Wayne,

          If the user copies/pastes the entire share embed code, that just inserts a generic map from Google, zoomed out to the whole world basically, and does not display the particular map view a user may be looking at and wishing to share. To make it work, they would have to copy just that specific portion of the embed code. Sadly, most users will be FAR to lazy to do that. They expect to simply be able to copy/paste the entire thing, wrap it in the tags, and be done with it. That is what the javacript I posted above allowed them to do before Google changed the URLs.
          Last edited by Tourmeister; Tue 7 Jun '16, 9:58am.
          Scott Friday
          Two Wheeled Texans

          Comment

          • Wayne Luke
            vBulletin Technical Support Lead
            • Aug 2000
            • 74154

            #6
            Then you will need to contact the person that originally wrote the javascript for you. Writing custom code is outside the scope of technical support.
            Translations provided by Google.

            Wayne Luke
            The Rabid Badger - a vBulletin Cloud demonstration site.
            vBulletin 5 API

            Comment

            widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
            Working...