javascript - Getting a "too much recursion" error with Google Maps + the places library - Stack Overflow

I have a form that implements a Google map with the Google places library (demo, as an aside, in JSFidd

I have a form that implements a Google map with the Google places library (demo, as an aside, in JSFiddle, if I add gmaps.js as a script reference it won't work but if I add it as a script element in the HTML section the exact same script works fine) that looks like so:

<form action="#" method="post">
  <table class='Information table table-bordered'>
    <caption>Information</caption>
    <colgroup>
      <col width='100' />
      <col/>
    </colgroup>
    <tbody>
      <tr>
        <th>Location</th>
        <td>
          <div class="input-append">
            <input type="text" name="Lat" value="37.771424" />
            <span class="add-on">lat.</span>
          </div>
          <div class="input-append">
            <input type="text" name="Lng" value="-122.41332799999998" />
            <span class="add-on">lng.</span>
          </div>
        </td>
      </tr>
      <tr>
        <th>Map</th>
        <td>
          <div id="panel">
            <form class="form-search">
              <input type="text" class="input-medium search-query" autoplete="off" id="target" placeholder="Search Box"/>
            </form>
          </div>
         <div id="ScavengerMap"></div>
        </td>
      </tr>
    </tbody>
  </table>
</form>

With the following JavaScript:

var input = document.getElementById('target'),
  searchBox = new google.maps.places.SearchBox(input),
  map = new GMaps({
    div: '#ScavengerMap',
    lat: 37.771424,
    lng: -122.41332799999998
  });
google.maps.event.addListener(searchBox, 'places_changed', function () {
  var places = searchBox.getPlaces(),
    location;
  if (places.length > 0) {
    location = places[0].geometry.location;
    map.removeMarkers();
    map.setCenter(location.jb, location.kb);
    map.addMarker({
      lat: location.jb,
      lng: location.kb,
      title: "Slim\'s",
      draggable: true,
      dragend: function (e) {
          var point = e.latLng;
          $('input[name=Lat]').val(point.lat());
          $('input[name=Lng]').val(point.lng());
      }
    });
    $('input[name=Lat]').val(location.jb);
    $('input[name=Lng]').val(location.kb);
  }
});

map.addMarker({
  lat: 37.771424,
  lng: -122.41332799999998,
  title: "Slim\'s",
  draggable: true,
  dragend: function (e) {
    var point = e.latLng;
    $('input[name=Lat]').val(point.lat());
    $('input[name=Lng]').val(point.lng());
  }
});

When you type something in the search box ("Slim's" for example) you will see a set of suggestions from the Google Places library. If you select one, it is supposed to draw a marker at that location, but instead I get these two errors:

too much recursion
[Break On This Error]   

...))};sa(fg[E],function(a){var b=this.ua,c=Sf(a);b[c]&&(delete b[c],O[m](this,vf,a...

{main,places}.js (line 26)
too much recursion
[Break On This Error]   

....route=function(a,b){Mf("directions",function(c){c.pi(a,b,!0)})};function P(a,b,...

The thing that I'm having a hard time working out is why. The code that is in this demo is a subset of the code in my project, but both present the same issue. I can't find any information about a Google Places Library or Google Maps API outage, and weirder still this exact same code worked as early as 2 weeks ago (the time I wrote it). Any ideas about how I could at least isolate the problem?

I have a form that implements a Google map with the Google places library (demo, as an aside, in JSFiddle, if I add gmaps.js as a script reference it won't work but if I add it as a script element in the HTML section the exact same script works fine) that looks like so:

<form action="#" method="post">
  <table class='Information table table-bordered'>
    <caption>Information</caption>
    <colgroup>
      <col width='100' />
      <col/>
    </colgroup>
    <tbody>
      <tr>
        <th>Location</th>
        <td>
          <div class="input-append">
            <input type="text" name="Lat" value="37.771424" />
            <span class="add-on">lat.</span>
          </div>
          <div class="input-append">
            <input type="text" name="Lng" value="-122.41332799999998" />
            <span class="add-on">lng.</span>
          </div>
        </td>
      </tr>
      <tr>
        <th>Map</th>
        <td>
          <div id="panel">
            <form class="form-search">
              <input type="text" class="input-medium search-query" autoplete="off" id="target" placeholder="Search Box"/>
            </form>
          </div>
         <div id="ScavengerMap"></div>
        </td>
      </tr>
    </tbody>
  </table>
</form>

With the following JavaScript:

var input = document.getElementById('target'),
  searchBox = new google.maps.places.SearchBox(input),
  map = new GMaps({
    div: '#ScavengerMap',
    lat: 37.771424,
    lng: -122.41332799999998
  });
google.maps.event.addListener(searchBox, 'places_changed', function () {
  var places = searchBox.getPlaces(),
    location;
  if (places.length > 0) {
    location = places[0].geometry.location;
    map.removeMarkers();
    map.setCenter(location.jb, location.kb);
    map.addMarker({
      lat: location.jb,
      lng: location.kb,
      title: "Slim\'s",
      draggable: true,
      dragend: function (e) {
          var point = e.latLng;
          $('input[name=Lat]').val(point.lat());
          $('input[name=Lng]').val(point.lng());
      }
    });
    $('input[name=Lat]').val(location.jb);
    $('input[name=Lng]').val(location.kb);
  }
});

map.addMarker({
  lat: 37.771424,
  lng: -122.41332799999998,
  title: "Slim\'s",
  draggable: true,
  dragend: function (e) {
    var point = e.latLng;
    $('input[name=Lat]').val(point.lat());
    $('input[name=Lng]').val(point.lng());
  }
});

When you type something in the search box ("Slim's" for example) you will see a set of suggestions from the Google Places library. If you select one, it is supposed to draw a marker at that location, but instead I get these two errors:

too much recursion
[Break On This Error]   

...))};sa(fg[E],function(a){var b=this.ua,c=Sf(a);b[c]&&(delete b[c],O[m](this,vf,a...

{main,places}.js (line 26)
too much recursion
[Break On This Error]   

....route=function(a,b){Mf("directions",function(c){c.pi(a,b,!0)})};function P(a,b,...

The thing that I'm having a hard time working out is why. The code that is in this demo is a subset of the code in my project, but both present the same issue. I can't find any information about a Google Places Library or Google Maps API outage, and weirder still this exact same code worked as early as 2 weeks ago (the time I wrote it). Any ideas about how I could at least isolate the problem?

Share Improve this question edited Aug 7, 2013 at 0:52 Jason Sperske asked Aug 7, 2013 at 0:36 Jason SperskeJason Sperske 30.5k8 gold badges76 silver badges127 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Looks like I figured it out. It seems the properties .jb and .kb have been renamed. The correct method to grab lat and lng is by calling .lat() and .lng() on the places[0].geometry.location object. My mistake for following an example too closely :)

You can check a about your zoom setting too. If you don't have a number for zoom setting this problem will appear.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744377318a4571251.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信