geolocation with javascript and ruby on rails

geolocation with javascript and ruby on rails

本文关键字:on rails ruby and with javascript geolocation      更新时间:2023-09-26

view.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() 时,但它只发出警报

警报("在 loc1233 中");

它不会转到该函数中的其余部分。为什么要这样给予?

谢谢

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

          $(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')
             }
             });