0

视图.html.erb

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

切换.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);
 });
 });

在这里调用toggle.js中的函数location(),但它只给出警报

alert("在 loc1233");

它不会转到该函数中的其余行。为什么要这样奉献?

谢谢

4

1 回答 1

0

为什么要在 jQuery 对象中编写函数?errorFunction 写在哪里?

          $(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')
             }
             });
于 2012-08-10T11:35:39.747 回答