-1

I have below code to find user current location.

if (navigator.geolocation) {
        // Get current position
        navigator.geolocation.getCurrentPosition(function (position) {
          myLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
          alert(myLatLng);
        },
        function () {
          alert('fallback');
        });
     }

Above code works fine but it prompts the user asking 'would you like to share your location with www.something.com?'. Now if user does not want to share his location then I need to show some alert. How can I do that?

user755806
  • 6,565
  • 27
  • 106
  • 153

1 Answers1

0

Your code is working fine you can see here.

<a href="https://jsfiddle.net/4cbuhhj2/">This jsfiddle</a>
  • It works when you select share location option. If i select 'Not Now' option, I need to get different alert. – user755806 Jul 21 '15 at 11:17
  • In which browser you are trying. I am trying in chrome and its asking me for "Js fiddle want to know your location" and option is allow and block only. – Raj Bahadur Singh Jul 21 '15 at 12:05
  • try this http://stackoverflow.com/questions/5947637/function-fail-never-called-if-user-declines-to-share-geolocation-in-firefox – Raj Bahadur Singh Jul 22 '15 at 12:04