Here We Are Again

Welcome back friends. This is the third season of You Are Here (with Safari on iPhone) and this series doesn’t look like it’s letting up any time soon. :)

Since our last installment in February 2010, it seems that the Google Maps API has shifted yet again and bricked our demo. No worries. Thanks to some great detective work by @Chris, we can get the old code up-and-running again by adding “optimized:false” to our Maps API Marker options. This will prevent Google from optimizing (encoding) the Marker image and allow the Marker to be rendered as an image tag as it did in our first demo. Therefore we can revert to our original CSS selector and call it a day.

But why leave it at that? Let’s take this to the next level and tweak that pulsating marker so it looks even more realistic.

Blue dot special

First off, let’s start with a fresh new marker—one that just encompasses that blue aqua icon at the center of the pulsating ring. I basically just recreated the blue iPhone Maps location icon in Fireworks and exported it as a PNG with alpha transparency. After uploading the image to the server, I also updated the Marker options to reflect the new file name and image size (17px square).

Great rings of Neptune, Batman!

Next up, the pulsating ring. Back in April 2010, Zachary Johnson posted a piece on Pure CSS Map Markers that inspired me to go 100% CSS on the rings. It just took me this long to get around to it.

To start, we’ll make a circle out of a square div by adding mega border-radius to it. In our case, we’ll have a 51px square (three times the blue icon’s height/width) with border-radius set to 51px as well. Now that we have our circle, let’s style it to look more like that iPhone Maps ring. Look closely at that ring and notice that its not a blue ring but a white ring with blue blurring the edges. We can achieve that effect by adding a 1px solid white border to our circle and then—and here’s the magic—applying multiple layers of blue inner and outer box-shadows in the same CSS declaration.

  1. box-shadow:
  2. inset 0 0 5px #06f,
  3. inset 0 0 5px #06f,
  4. inset 0 0 5px #06f,
  5. 0 0 5px #06f,
  6. 0 0 5px #06f,
  7. 0 0 5px #06f;

Who knew you could do such a thing? I didn’t, until I tried it. The ability to use standard drop shadows and inset shadows in the same declaration is amazing enough, but that you can layer them to achieve deeper color (as you would in Photoshop with multiply layers) is astonishing. And we’ll need this color depth when we animate our ring. Without this color depth, the blue would appear too faint as its opacity drops to zero.

So, all that remains in our styling exercise is to animate our awesome ring. Going back to our keyframes, let’s start from an initial scale of 25% and opacity of 100%. Then let’s progress at the 95% mark to 130% scaling and 0% opacity. And lastly, let’s return to scale of 25% with the 0% opacity to reset everything for the next iteration. That’s pretty much it—aside from some refactoring to take advantage of animation shorthand and the addition of Mozilla’s CSS prefix,

Okidoki. So we have our new blue icon marker and we have a new pulsating ring, but they’re not connected. We need to dig into the Google Maps DOM and grab our marker’s wrapper element to apply the ring styling (so that the ring will pulsate out from the marker image). Fortunately, there’s a div that surrounds our marker image that meets our needs. Curiously, there are actually two almost identical div/marker-img combos to play with. We can actually sacrifice one for our sneaky purposes. The second combo has a div with the Marker title we added in the options so we can conveniently use that as our ring’s CSS selector. Yay! But since that div is scaling up and down, the inner bluedot.png img tag scales up and down too, which isn’t what we want. No problemo! Display:none that image and let the first set’s bluedot image shine through.

Add a few more margin tweaks for high DPI devices and we’re done styling our realistic pulsating marker. Check it out on the demo page.

Am I really here?

Commenter @John also mentioned some issues with geolocation accuracy thay @Ziyad was kind enough to address. Since we’re already under the hood, let’s roll those modifications into our code as well.

  1. navigator.geolocation.watchPosition(
  2. displayLocation,
  3. handleError,
  4. {
  5. enableHighAccuracy: true,
  6. maximumAge: 30000,
  7. timeout: 27000
  8. }
  9. );

Wait, what version is this?

This demo has had a history of API version issues so it comes as some relief to find Google providing support for versioning. I’m not sure if this is a recent development, but you can actually specify the Maps API version that your code works with. So now when our code breaks, just go back and request the API script version that was running back when things were good.

  1. http://maps.googleapis.com/maps/api/js?v=3.4&sensor=true_or_false

Git it while it’s hot!

Speaking of versioning, the code for this demo is now up on GitHub. Go grab it from there, fork it, enjoy.

demo code

30 Comments (+)

  1. Tony Jillson

    HI Steve,
    FYI, the blue dot is not centered within the rings of saturn, at least not on my iPad. The dot appears down and to the right.

    My Main question is, can you combine your ‘you are here’ with a custom map? I have created a custom map with 23 markers that load from an xml file.

    Can I have this map, as well as the blue dot? (I’m creating a walking tour for a local museum)

    Thanks!

  2. Steve Stedman

    @Tony thanks for catching the off-center rings in iPad. I fixed that bug with an additional media query on line 60.

    Regarding the custom map, it looks like you can customize the tile overlays and I bet you can loop though a list of additional markers (just make sure they don’t share the same title as the pulsating marker).

  3. Shaun Bent

    Hi Steve,

    Love this code snippet – spent a long time searching for how to achieve this effect.

    One question though did you create ‘bluedot.png’ yourself or did you download it from somewhere?

    I am only asking as I need a version twice the size so that I can serve it up and scale it down using Google Maps API so that it remains nice and sharp on retina devices.

    Something like this: http://samcroft.co.uk/2011/google-maps-marker-icons-for-iphone-retina-display/

    This might be a nice improvement to your code overall as if you have gone to the trouble of fixing the pulse for retina devices, so might as well fix the icon. If you could provide the image I do not mind implementing it and sharing the code? Any help you could provide would be awesome.

    Again thanks

    Shaun

  4. Steve Stedman

    @Shaun glad you found the snippet helpful!

    To answer your question about the bluedot image: yes, I created that PNG in Fireworks. Your point about doubling its size for Retina Display is well taken and I’ll take a shot at doing just that when I can. Also, after reading Sam Croft’s article on high-res markers, I can see that I’ll need to make a few changes to my code. Thanks for the link!

    In the meantime, I uploaded my original Fireworks source file to GitHub (under the source directory). If you want to take a swing at updating the image (and the JavaScript) for Retina Display, by all means fork that repo and shoot me a pull request. I’d sincerely appreciate it! –Thanks!

  5. Steve Stedman

    @Shaun, I found a spare moment and updated the Marker and JavaScript code per Sam’s article. Thanks again for noticing that Retina Display issue and proposing a solution. It worked!

    And thank you Sam Croft, where ever you are.

  6. Shaun Bent

    Thank you for looking into this Steve.

    I wasn’t expecting you to implement it as well.

    Thanks again

    Shaun

  7. Phillip

    I had good luck with this on Chrome but I cannot get it to work on my iPhone. Instead of #map_canvas I am using Sencha Touch so I tried setting it up with .x-map which I thought would work and still only works on Chrome but not iPhone.

  8. Sam Croft

    @steve I’m here! You’re welcome :)

    This is a great technique, very clever and creative.

    - Sam

  9. Todd Blanchard

    Really cool snippet. I’ve tried it on my iPhone 4GS and in my browser and it works as expected. On a 3GS, the ring is offset upwards and to the left though. :-(

  10. Tony Jillson

    @Steve
    We’re doing some testing now that we’ve reconciled your ‘blue dot’ map with our custom embedded map.
    The geolocation accuracy script helped quite a bit.
    But we’ve run into an issue where the dot doesn’t follow you around in real time. You have to update the page each time to see where you are. This is in Safari on iPad.
    Do you know if it’s possible to have the dot follow you around in real time like it does in the ‘Maps’ app? Or does it necessitate a page refresh each time?

  11. Ross Shannon

    Changing the mobile-specific part at the end of the CSS from “#map_canvas …” to “#map …” solves the off-center blue dot problem. Thanks for this code Steve.

  12. Google Map現在地アイコン/レーダのようにパルス発信するアニメーション | WordPressにGoogle Maps API V3!ブログ素人のホームページの作成メモ

    [...] plebeosaur.us ”Here We Are Again” [...]

  13. Ben

    @Steve : Thanks for your code !
    @Todd : i had the same problem with a 3GS. I used snippet code found here and now all is ok on a 4S and 3GS http://css-tricks.com/snippets/css/media-queries-for-standard-devices/

  14. Johan Sundström

    Thanks for doing this! If you git checkout -b gh-pages ; git push -u origin gh-pages from your master branch, you’ll get an automatically github-hosted result of the second branch like http://johan.github.com/GeoLocateMe/ (but for your github user name’s). You can even drop master and only have the latter, for ease of updates.

    The blue marker image could use a little smoother alpha channel transition from transparent to its outer rim; it looks a little pixely-jagged at the moment.

  15. Mustafa

    Great tutorial. I’m trying to recreate this on Bing Maps but I can’t figure out how to get the blue dot to appear. The rings appear and pulsate fine, just no blue dot.

    I’m guessing it has to do with the way Bing uses its Icon Image. Any ideas?

  16. Paul O

    Thank-you for this! Now I’ve gotta sleep on it for a day or so, and play with it a while, but if I want to change the size of the outer rings to reflect the “accuracy” of the geolocation (where available), I presume I can modify the style in the DOM in the watchPosition handler. Maybe if I want to get really fance I can couple the scale of the pulsar with the accuracy of the geolocation *and* the scale of the map as the user zooms in or out.

    I’ve just gotta study it to figure out what to modify … unless you’ve got a quick answer …

  17. Stephane

    That example is so good! Thank you for sharing it. It took me a bit of time to figure out why it was not working at first and it turned out to be the CSS selector issue using the “I might be here” title. I was using a different dynamic one.

    Is there another way to still select the right element to style when a dynamic custom title is used with possibly multiple markers. What it seems to be is that there has to be a static way to select it (or them if i have many markers).

    Thanks for reading!

  18. Ptitfilou

    Because you’re just the kind of people that I like to thank, for your work that still work two years after, and is robust, clear and easy to use.

    Thank you

  19. Adultwebcamsexchat.Com

    Fairly portion of content material. I just now became aware of your site plus accession capital to mention that we have basically loved account ones blog page posts. In whatever way I will be registering to your own provides nourishment to and perhaps My partner and i fulfillment you will get admission to regularly rapid.

  20. Maarten

    Really awesome! This made my map application from good to perfect!

  21. cheap capitals jerseys

    9999 The job you’ve got carried out has gotten you this much. These station reproduction handbags in many cases are the clone for your genuine breathtaking channel totes.
    cheap capitals jerseys http://www.brooksandbrooksfoundation.org/washington-capitals-jerseys-c-9_24.html

  22. black friday deals for christian louboutin

    9999 The do the trick you’ve conducted has gotten you this considerably. These station reproduction handbags tend to be the clone for your genuine good-looking channel totes.
    black friday deals for christian louboutin http://www.brooklynphotoblog.com/black-Friday-louboutin.html

  23. cheap nfl jerseys

    9999 The job you’ve got conducted has gotten you this significantly. These station replica handbags in many cases are the clone for the genuine striking channel totes.
    cheap nfl jerseys http://www.garden-addiction.com

  24. Tower of Saviors Hack

    You happen to be a classic great site owner. The internet site loading speed is definitely amazing. It sort of feels you are doing almost any special trick. As well, Your articles are generally must-see. you will have completed an excellent activity about this matter!

  25. Wie Schnell Abnehmen

    Appreciating the hard work you put into your site and detailed information you provide.
    It’s awesome to come across a blog every once in a while
    that isn’t the same unwanted rehashed material. Excellent read!

    I’ve saved your site and I’m including your RSS feeds
    to my Google account.

    Also visit my web-site; Wie Schnell Abnehmen

  26. Samurai siege hack

    Interesting section of content material. I just discovered your web site plus in accession cash to talk about we obtain basically loved consideration your web site posts. Any way My business is opt-in with your augment and also We achievement you admittance persistently swiftly.

  27. Marvel run jump smash hack

    Thanks for another wonderful write-up. The location altogether different could anybody get that form of facts in this a good way regarding composing? I’ve got a display pursuing 7 days, and I am within the search for like info.

  28. buy cheap louis vuitton luggage

    cheap nike nfl jerseys buy cheap jerseys online from china, wholesale price & free shipping buy cheap jerseys free shipping online, high quality & wholesale price cheap nfl jerseys online hot sale, wholesale price & free shipping cheap nba jerseys nhl jerseys china wholesale cheap nike 49ers jerseys wholesale mlb jerseys 2013 cheap free shipping wholesale jerseys china cheap jerseys online – buy wholesale nfl, nba, mlb, nhl & soccer jerseys with free shipping cheapest soccer team jerseys authentic nfl football jerseys wholesale cheap authentic jerseys from china nhl jerseys from china cheap cheap nba jerseys for nfl jerseys sale cheap quality guaranteed nfl jerseys china clearance sale cheap nfl youth jerseys free shipping discount cheap nike nfl jerseys paypal soccer jerseys from china
    buy cheap louis vuitton luggage http://www.claygateallotments.org/discuss/cheap_louis_vuitton_luggage_603.aspx

  29. louis vuitton outlet online

    louis vuitton outlet online replica christian louboutin shoes replica christian louboutin boots replica christian louboutin replica christian louboutin shoes red bottom shoes outlet red bottoms heels replica christian louboutin boots red bottoms outlet replica christian louboutin shoes cheap authentic christian louboutin shoes where to buy christian louboutin red bottoms for men shoes christian louboutin boots sale discount red bottoms shoes men authentic louis vuitton outlet christian louboutin candy shoes australia online r christian louboutin canne rosso red bottoms store is there a christian louboutin outlet

  30. New Fitflop Three Diamond Sandals Black

    Barbour Jackets ChtP,ChtP Cheap Fitflop Shoes ChtP,ChtP Barbour Sale ChtP,ChtP fitflops on sale ChtP,ChtP fitflop online ChtP,ChtP barbour sale ChtP,ChtP barbour quilted jacket ChtP, ChtP nike jordan ChtP,ChtP ChtP jordan 13 ChtP,ChtP jordan retro 5 ChtP,ChtP nike online ChtP,ChtP nike running shoes ChtP,ChtP cheap jordans for sale ChtP,ChtP air jordan shoes ChtP,ChtP Fitflop Dass ChtP,ChtP Vibram FiveFingers Bikila ChtP,ChtP Vibram Five Fingers Bikila LS ChtP,ChtP nike store ChtP,ChtP Jordan Shoes ChtP,ChtP Barbour Waterproof Jackets ChtP.ChtP Fitflops Shoes UK ChtP.
    New Fitflop Three Diamond Sandals Black http://www.migrationstation.com/new-fitflop-three-diamond-sandals-black-p-396.html/

Leave a Reply