We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37242 ☆ A M B ☆
    • 339 Posts
    Hi,

    i am currently working on an improvement of an existing module. i am running into some JavaScript Issues, as i am trying to get lat / lon out of an address, where no lat / lon is given.

    As i am not the Javascript guy, i could use some help.

    Here, i (guess) i am calling "findlocation", which should fill out the missing values plc[1] and plc[2].

                $js .= '
        var infobulle = new google.maps.InfoWindow();
        var bounds = new google.maps.LatLngBounds();
        for (var i = 0; i < places.length; i++) {
            plc = places[i];
            if ((plc[1] == undefined) && (plc[2] == undefined)) {
    		plc = findlocation(plc);
            	ptPlc = new google.maps.LatLng(plc[1], plc[2]);
            }
            else {
            	ptPlc = new google.maps.LatLng(plc[1], plc[2]);
            }
         		bounds.extend(ptPlc);
          	var markerPlace = addMarkerPlace(ptPlc, plc, map, imgMkrs, infobulle);
            }
        map.fitBounds(bounds);';


            function findlocation(plc) {
    	if (geocoder) {
    		//format address
    			if (plc[6] !== undefined && plc[7] !== undefined && plc[8] !== undefined) {
    				plc.address = plc[6] + ", " + plc[8] + ", " + plc[7];
    			} else if(plc[6] !== undefined && plc[8]) {
    				plc.address = plc[6] + ", " + plc[8];
    			} else {
    				plc.address = null;
    			}
    
    	if (plc.address !=null) {
    	    geocoder.geocode( { "address": plc.address}, function(results, status) {
    	      if (status == google.maps.GeocoderStatus.OK) {
    	      	plc[1] = results[0].geometry.location[\'Da\'];
    	      	plc[2] = results[0].geometry.location[\'Fa\'];
    //	      	       alert(dump(plc));
    		return plc;
    	      }
    	      else {
    	        alert("Geocode was not successful for the following reason: " + status);
    	      }
    	    });
        }
    	}
    }


    What could be wrong, that plc is undefined after I call findlocation?
    I am thankful for any help smiley

    Guido
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      Quote from: dogo at Apr 09, 2011, 06:26 AM

      if (plc.address !=null) {
      So, plc is an array or an object?
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 37242 ☆ A M B ☆
        • 339 Posts
        An array. When i alert the dump of plc, its mentioned like it was an associated index [’address’] => ’bla bla dicdcindvc’
          • 37242 ☆ A M B ☆
          • 339 Posts
          This is var places, each line is a plc:
              var places = [
                  [ "Wolf Birke", 46.538362, 2.427753, "13", "mitglieder/wolf-birke.html", "", "Luisenstraße 87a", "", "", ],
                  [ "Guido Gallenkamp", , , "14", "mitglieder/guido-gallenkamp.html", "", "Laurentiusstraße 24", "42103", "Wuppertal", ],
              ];


          Origin: http://bergischer-ring.bytethinker.com/extratouren.html
            • 11055 ☆ A M B ☆
            • 3,112 Posts
            try to rename plc.address to be something else.
            like
            function findlocation(plc) {
                var address='';
                if (geocoder) {
                    //format address
                    if (plc[6] !== undefined && plc[7] !== undefined && plc[8] !== undefined) {
                        address = plc[6] + ", " + plc[8] + ", " + plc[7];
                    } else if(plc[6] !== undefined && plc[8]) {
                        address = plc[6] + ", " + plc[8];
                    } else {
                        address = null;
                    }
            
                    if (address !=null) {
                        geocoder.geocode( {
                            "address": address
                            }, function(results, status) {
                            if (status == google.maps.GeocoderStatus.OK) {
                                //	      	plc = results[0].geometry.location['Da'];
                                //	      	plc = results[0].geometry.location['Fa'];
                                //	      	       alert(dump(plc));
                                return results[0].geometry.location ;
                            }
                            else {
                                alert("Geocode was not successful for the following reason: " + status);
                            }
                        });
                    }
                }
            }
            
              Rico
              Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
              MODx is great, but knowing how to use it well makes it perfect!

              www.virtudraft.com

              Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

              Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

              Maintainter/contributor of Babel

              Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
              • 37242 ☆ A M B ☆
              • 339 Posts
              No results yet sad

              I really dont understand why "plc.address" is beeing set (an can be asessed outside the function), but "geopos" is not.

                      function findlocation(plc) {
              	if (geocoder) {
              		//format address
              			if (plc[6] !== undefined && plc[7] !== undefined && plc[8] !== undefined) {
              				plc.address = plc[6] + ", " + plc[8] + ", " + plc[7];
              			} else if(plc[6] !== undefined && plc[8]) {
              				plc.address = plc[6] + ", " + plc[8];
              			} else {
              				plc.address = null;
              			}
              
              	if (plc.address !== null) {
              		      alert("address is set");
              		      var geopos = null;
              	    geocoder.geocode( { "address": plc.address}, function(results, status) {
              	      if (status == google.maps.GeocoderStatus.OK) {
              	      alert ("Status is OK");
              	      	geopos.lon = results[0].geometry.location[\'Da\'];
              	      	geopos.lat = results[0].geometry.location[\'Fa\'];
              alert(dump(geopos));
              				return geopos;
              	      }
              	      else {
              	        alert("Geocode was not successful for the following reason: " + status);
              	      }
              	    });
                  }
                  else {alert("address not set");}
              	}
              }


              I tried to call "plc.address" "address", but it had no effect on the results. What i need is plc[1] and plc[2] to be set and accessed outside of findlocation(plc) sad