0

view.html.erb

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
 location();
</script>

toggle.js

$(document).ready(function() {

$(function location()
{
  alert("here in loc1233");

  if (navigator.geolocation) {
     navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
  } 
  else {
   alert("here in loc");
  }
 });    //showmap

 $(function successFunction(position) {
    var lat = position.coords.latitude;
    var lot = position.coords.longitude;
   alert('Your location coordinates are: Latitude:'+lat+' Longitude: '+lot);
 });
 });

Here when call the function location() in toggle.js, but its only give the alert

alert("here in loc1233");

its doesn't go to that rest of the line in that function. Why giving like that?

thanks

1

1 Answer 1

0

Why you writing functions in jQuery object?? and where is the errorFunction written??

          $(document).ready(function() {
            $(function location()
            {
              alert("here in loc1233");
              if (navigator.geolocation){navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
              } 
              else {
               alert("here in loc");
              }
             });    //showmap
             function successFunction(position) {
                var lat = position.coords.latitude;
                var lot = position.coords.longitude;
               alert('Your location coordinates are: Latitude:'+lat+' Longitude: '+lot);
             }
             function errorFunction(position){
                alert('alert')
             }
             });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.