简体   繁体   English

智能手机设备上的地理位置无法运行

[英]Geolocation on smartphone devices doesn't run

in my website I have to launch google maps for driving directions when I click on a button. 在我的网站上,当我单击按钮时,我必须启动Google地图以获取行车路线。 I know the end point but I must communicate the starting point, that's my position, with geolocation. 我知道终点,但是我必须通过地理位置传达起点,这就是我的位置。 I've a problem with geolocation on smartphone devices. 我在智能手机设备上的地理位置问题。 This is my code: 这是我的代码:

jQuery(window).load(function(){ if (navigator.geolocation) navigator.geolocation.getCurrentPosition(function(position){ myLat=position.coords.latitude; myLng=position.coords.longitude; jQuery(".btn").attr("href", "http://www.google.it/maps?saddr="+myLat+","+myLng+"&daddr=44.000000,7.000000")}; }); });

It works well on pc, but on smartphone it doesn't run. 它在PC上运行良好,但在智能手机上却无法运行。 An error occures. 发生错误。 Should I write a different href for these devices? 我应该为这些设备写一个不同的href吗? If so, how?? 如果是这样,怎么办? Thanks a lot for your help!! 非常感谢你的帮助!!

I think I solved it. 我想我解决了。 I detect if I'm using mobile devices and for them I use this code 我检测我是否正在使用移动设备,并且我使用了此代码

if( isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows()){
        jQuery(".btn").attr("href", "https://maps.google.com?saddr=Current+Location&daddr=44.000000,7.000000")
    }

Thank you for your support Riccardo 谢谢您的支持Riccardo

Look here if it can help you in some way. 查看它是否可以在某种程度上帮助您。 http://www.w3schools.com/html/html5_geolocation.asp http://www.w3schools.com/html/html5_geolocation.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM