I have coded a function showAddress1(...)
In this function, except the 2D array delivery[][] is global variable,
others are local variable.
I have a problem here.
Since the content of delivery[][] is updated in this function, I cannot
retrieve the updated content outside this function.
For example, when I call alert(delivery[0][1]), undefined value is returned.
I have attempted to return the delivery[][] in the function, it seems not to
work.
So, I want to ask, what is the correct approach to return the array content
delivery[][] I want.
Could anyone mind giving me some guideline to do so?
Thank you.
//in this function, I want to return the value of delivery[][] , but I don't
know how to do.
function showAddress1(address, m) {
if (geocoder) {
geocoder.getLatLng( address,
function(latlng) {
if (!latlng) {
window.alert("Incorrect Address: " + address);
} else {
var store_lat = 29.333047;
var store_lng = 116.187264;
latlng = latlng;
lat = latlng.lat();
lng = latlng.lng();
x = ( store_lat - lat ) * ( store_lat - lat );
y = ( store_lng - lng ) * ( store_lng - lng );
distance = Math.sqrt( x + y );
//I cannot access this value outside this function
delivery[m][1] = distance;
//no problem here, I can retrieve the value
alert(delivery[m][1]);
//how to return this value;
//return delivery[m][1];
}
} );
}
}
for ( m = 0; m < 11; m++ ) {
// call function
showAddress1(delivery[m][0], m );
}
//undefined value is returned, it is because the function cannot
return the array value
//alert(delivery[0][1]);
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.