Search code examples
javascriptgoogle-mapsdom-eventsgoogle-earthgoogle-earth-plugin

If Google earth plugin isn't installed switch to Google maps


I'm making some Google earth web apps at the moment that use the ge plugin. however, not everyone has it installed and as yet you can't get the plugin for mobile devices. I've put in a js check to see if the user has ge plugin or not. What I'd like to do is give the option of continuing and downloading the plugin OR switching to a Google maps version of the page.

Any ideas as to how best to do this?


Solution

  • If you display the plugin and the user doesn't have the plugin installed, it will automatically fill the target div with an Earth-y image and a button to install the plugin. So really, you just have to decide how to direct the user and provide a choice for them if they want one experience or the other.

    You can use

    google.earth.isSupported()
    

    to check if a platform isn't supported at all (for instance, on a mobile device), and if it returns false, automatically redirect to your Maps-based version of the page with no option to go back (since there's no way for them to run the Earth plugin).

    On platforms where isSupported() returns true, you can then use

    google.earth.isInstalled()
    

    to check if the plugin is installed. If that check returns false, you could redirect the user to the Maps-based page but include a button for installing the plugin, or you can leave them on the Earth-based page, which will include the "install Earth Plugin" button automatically, and you can put an additional button below that for the user to choose the Maps-based version if they don't want to install anything.

    If both functions return true, then you can obviously do whatever you want.

    Edit: actually, you seem comfortable with doing at least some of this already, so if you're just looking for a best practice for allowing switching between the two versions, I've found that just providing a link or a button below the plugin div is perfectly sufficient for most users.