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

amtest
  • 690
  • 1
  • 6
  • 26

1 Answers1

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')
             }
             });
Shreyas Agarwal
  • 1,128
  • 8
  • 10