daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setMaps() {
  2.     var geocoder = new google.maps.Geocoder();
  3.     var result = "";
  4.  
  5.     $('.map_canvas').each(function(){
  6.  
  7.         geocoder.geocode( {
  8.             'address': $(this).attr('address'),
  9.             'region': 'de'
  10.         }, function(results, status) {
  11.             if (status == google.maps.GeocoderStatus.OK) {
  12.                 result += results[0].geometry.location.lng()+",";
  13.                 result += results[0].geometry.location.lat();
  14.             } else {
  15.                 result = "Unable to find address: " + status;
  16.             }
  17.             $(this).gmap({ 'center': result });
  18.         });
  19.     });
  20. }
  21.    
  22. <div class="map_canvas" address="Berlin, Zoo">
  23.  
  24. </div>
  25.    
  26. Uncaught TypeError: Cannot set property 'position' of undefined
  27.    
  28. function setMaps() {
  29.     var geocoder = new google.maps.Geocoder();
  30.     var result = "";
  31.  
  32.     $('.map_canvas').each(function(){
  33.        var _this = $(this); // <------ here
  34.         geocoder.geocode( {
  35.             'address': $(this).attr('address'),
  36.             'region': 'de'
  37.         }, function(results, status) {
  38.             if (status == google.maps.GeocoderStatus.OK) {
  39.                 result += results[0].geometry.location.lng()+",";
  40.                 result += results[0].geometry.location.lat();
  41.             } else {
  42.                 result = "Unable to find address: " + status;
  43.             }
  44.             _this.gmap({ 'center': result }); // <---- and here
  45.         });
  46.     });
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top