javascript - js geolocation but without prompting - possible? - Stack Overflow

Is it possible to get the geolocation of a user without the browser prompt?Here's the code sample

Is it possible to get the geolocation of a user without the browser prompt?

Here's the code sample from W3

<script>
   var x = document.getElementById("demo")

   function getLocation(){
     if(navigator.geolocation){
       navigator.geolocation.getCurrentPosition(showPosition);
     } else {
       x.innerHTML="Geolocation is not supported by this browser.";}
     }
     function showPosition(position){
       x.innerHTML="Latitude: " + position.coords.latitude + 
       "<br>Longitude: " + position.coords.longitude;   
     }
</script>

Is there any preventPrompt()-like function ?

Is it possible to get the geolocation of a user without the browser prompt?

Here's the code sample from W3

<script>
   var x = document.getElementById("demo")

   function getLocation(){
     if(navigator.geolocation){
       navigator.geolocation.getCurrentPosition(showPosition);
     } else {
       x.innerHTML="Geolocation is not supported by this browser.";}
     }
     function showPosition(position){
       x.innerHTML="Latitude: " + position.coords.latitude + 
       "<br>Longitude: " + position.coords.longitude;   
     }
</script>

Is there any preventPrompt()-like function ?

Share Improve this question edited Feb 26, 2017 at 18:55 Trevor 1,4343 gold badges16 silver badges33 bronze badges asked Jan 26, 2013 at 16:23 doniyordoniyor 37.9k61 gold badges181 silver badges270 bronze badges 5
  • "the reason is, i am using the lat and longt to give of user, to give the user very important information about what the user is looking for." ... isn't this always the case when you want to use the user's location? ;) – Felix Kling Commented Jan 26, 2013 at 16:39
  • @FelixKling, yeah, you are right? :D – doniyor Commented Jan 26, 2013 at 16:40
  • 1 im very glad that my browser prevents people like you from disregarding my response to the prompt. – goat Commented Jan 26, 2013 at 17:17
  • @iputonmyrobeanwizardhat, my plan is good plan, dont worry – doniyor Commented Jan 26, 2013 at 17:21
  • you can try using 3rd party geo location API, like our ip-api.io – Andrey E Commented Aug 9, 2017 at 20:36
Add a ment  | 

2 Answers 2

Reset to default 3

No you cant prevent the prompt, its a security feature cause not every user wanna share its location.

From the W3C docs:

A conforming implementation of this specification must provide a mechanism that protects the user's privacy and this mechanism should ensure that no location information is made available through this API without the user's express permission.

But you can try to use a service like geoip in the error callback.

No, that's not possible.

The prompt is there so that the user can choose whether you know the location or not.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742305359a4418828.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信