Created
December 17, 2014 05:51
-
-
Save cellfusion/d57860a63a9b61b54362 to your computer and use it in GitHub Desktop.
iOS と Android でマップを開く時のコード(Google Map を優先)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# iframe で URL scheme を開く | |
iframe = $('<iframe>').css('display', 'none').attr('src', 'comgooglemaps://?q='+lat+','+lng+'&z='+zoom).appendTo('body') | |
start = Date.now() | |
# URL scheme の反応がない場合にこちらで開く | |
# 通常だとアプリがない場合は iOS はダイアログがでるがこのコードだとダイアログを回避して iOS Map で開くことができる | |
setTimeout ()-> | |
diff = Date.now() - start | |
if diff < 2000 | |
# だめだった場合に Map で開く | |
# Android の場合は Google Map で開く | |
window.location.href = 'http://maps.apple.com/maps?q='+lat+','+lng+'&zoom='+zoom | |
# いらなくなった iframe を削除 | |
iframe.remove() | |
, 500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment