Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a function that requires a second function work properly.
I delcare 2 variables before either function begins.
The first function sends info to the second and the second function is supposed to assign the 2 variables the longitude and latitude of the address sent. for testing reasons, i do an alert of the variables in both functions. The second does fine, but the first function doesn't recieve the variables. To my understanding, if the variable is declared outside of the functions it should be global... but that doesn't seem to be the case.
[syntax="javascript"]
<script type="text/javascript">
//<![CDATA[
var lat;
var lon;
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();
map.setCenter(new GLatLng('38.36626','-095.780260'), 4);
map.addControl(new GLargeMapControl());
map.addControl(new GOverviewMapControl());
map.addControl(new GMapTypeControl());
// Create our "tiny" marker icon
var icon = new GIcon();
icon.image = "http://uppi.biodose.com/mod/phpwsbusinesses/img/both.gif";
icon.iconAnchor = new GPoint(1, 17);
icon.infoWindowAnchor = new GPoint(5, 1);
var icon1 = new GIcon();
icon1.image = "http://uppi.biodose.com/mod/phpwsbusinesses/img/cyc.gif";
icon1.iconAnchor = new GPoint(1, 17);
icon1.infoWindowAnchor = new GPoint(5, 1);
}
// Add 10 markers to the map at random locations
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var point = new Array();
map.addOverlay(createMarker(new GLatLng('38.36626','-095.780260'), icon1, 'asdf'));
geocoder.getLocations('3940 South Eastern Ave, Las Vegas, Nevada, 89119, usa', alertAddress); // sends the address to alertAddress function and it shouldset lat and lon to the correct coordinates.
alert(lat+', '+lon); // ouputs "undefined, undefined" (quotes not included)
map.addOverlay(createMarker(new GLatLng(lat, lon), icon, 'asdf')); //doesn't work because lat and lon are undefined.
}
// Creates a marker at the given point with the given number label
function alertAddress(point){
lat = point.Placemark[0].Point.coordinates[1];
lon = point.Placemark[0].Point.coordinates[0];
alert(lat+' | '+lon);// ouputs "36.241234, -115.23421" (quotes not included) These are the corrcet coordinates
}
// createMarker function works just fine with everything.
// Creates a marker at the given point with the given number label
function createMarker(point, icon, number) {
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml("Marker #<b>" + number + "</b>");
});
return marker;
}
load();
//]]>
</script>
If I was confusing or if you need more info, please ask away.
Thanks in advance for everyone's time and effort.
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]