【问题标题】:geolocation with javascript and ruby on rails在 Rails 上使用 javascript 和 ruby​​ 进行地理定位
【发布时间】:2012-08-10 11:08:17
【问题描述】:

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);
 });
 });

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

alert("在 loc1233");

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

谢谢

【问题讨论】:

标签: javascript ruby-on-rails ruby html ruby-on-rails-3.1


【解决方案1】:

为什么要在 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')
             }
             });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 2010-11-22
    • 2012-01-04
    • 1970-01-01
    • 2012-05-12
    • 2010-11-12
    相关资源
    最近更新 更多