Google Map - Flying Ladybug (US)

The code snippet below allows you to add a ladybug (or any other image), to fly over a map. The coordinate boundaries are for the United States (min_lon, min_lat, max_lon, max_lat), but you can change them to suit your needs.

After a random number of seconds, the ladybug lands on the map. When the site visitor moves the mouse over the ladybug, she will fly to a different, random point on the map. This continues forever. The site visitor will tire of this long before the ladybug does. :)

This piece of code was named cartesian/optimize.js and included into page with a script tag. This allows you to quickly remove the code prior to deployment.

Recommended application … none. This is strictly for fun.

var bugIcon = new GIcon();
        bugIcon.iconSize=new GSize(32,32)
        bugIcon.shadowSize=new GSize(0,0)
        bugIcon.iconAnchor=new GPoint(16,32)
        bugIcon.infoWindowAnchor=new GPoint(16,0)
var bugFlag = new GIcon(bugIcon,'cartesian/bug.gif',null,null)

min_lon=-70
min_lat=30
max_lon=-130
max_lat=50
lat_range=max_lat-min_lat
lon_range=max_lon-min_lon
lat=(Math.random()*lat_range)+min_lat
lon=(Math.random()*lon_range)+min_lon

var bug=0

function makeBug()
{
bug=new GMarker(new GLatLng(lat, lon),bugFlag)
map.addOverlay(bug)
GEvent.addListener(bug, "mouseover", flyBug)
}

function flyBug()
{
lat=(Math.random()*lat_range)+min_lat
lon=(Math.random()*lon_range)+min_lon
map.removeOverlay(bug)
delete bug
bug=new GMarker(new GLatLng(lat, lon),bugFlag)
map.addOverlay(bug)
GEvent.addListener(bug, "mouseover", flyBug)
}

window.setTimeout("makeBug()", 25000*Math.random());