2

newbie question here.. I'm trying to return the LAT LNG values from the array.

I have the following three functions:

function City(ridge)
{
    var city=   {
    ABC:"Bethel, AK",
    ABR:"Aberdeen, SD",
    ABX:"Albuquerque, NM"};
    return city[ridge];
}

and

function BBox(ridge,product)
{
    var yx= {
    NOR:
    {
    ABC:[64.835517,56.735755,-157.448578,-166.284681]
    ,
    ABR:[48.270508,42.631241, -95.331912,-101.483839]
    ,
    ABX:[37.565036,32.726169,-104.179217,-109.457981]}};
    var xy=yx[product][ridge];
    return {x0:xy[2],x1:xy[3],y0:xy[0],y1:xy[1]};
}

and

function initialize()
{
var ridge =  'ABC';
var product ='NOR';
var getCityInfoFromRidgeName = City(ridge);
var boundries=BBox(ridge,product);
alert(getCityInfoFromRidgeName);
alert(boundries);
}

the alert for City returns "Bethel, AK" as expected.. but the alert for BBox returns "objec Object" instead of the LAT LNG information as hoped.

I'm probably in over my head, but how can I return the LAT LNG from the BBox to a var?

Den

Jimmery
  • 9,783
  • 25
  • 83
  • 157
  • possible duplicate of [how to alert javascript object](http://stackoverflow.com/questions/3580754/how-to-alert-javascript-object) – jbabey Jan 25 '13 at 13:17
  • 1
    he wants to know how to return values from on object into a variable - not how to convert an object into a string to be alerted. – Jimmery Jan 25 '13 at 13:25
  • @Jimmery "but the alert for BBox returns "object Object" instead of the LAT LNG information as hoped." pretty sure it's an exact duplicate. – jbabey Jan 25 '13 at 13:35
  • 1
    @jbabey - read the last line, you know, the line with the question mark on it - "but how can I return the LAT LNG from the BBox to a var?" - he is just using alert to see if he has the right values, but what he actually wants to do is put a value from BBox into a variable. – Jimmery Jan 25 '13 at 14:29
  • @Jimmery he's already doing that: `return {x0:xy[2],x1:xy[3],y0:xy[0],y1:xy[1]};` works fine. – jbabey Jan 25 '13 at 14:38
  • @jbabey you obviously dont understand his question. i obviously did as he marked my answer as correct. – Jimmery Jan 26 '13 at 11:46

1 Answers1

1

boundries is an object holding the x and y coords. you can get at the coords with this code:

alert(boundries.x0);
alert(boundries.x1);
alert(boundries.y0);
alert(boundries.y1);

for future reference, objects in javascript can be created like this:

var anObject={property:'value'};
var anotherObject={
    message:'Hello',
    location:'World',
    aNumber:23
};

and then parts of an object can be accessed with a dot - like this:

anObject.property;
alert(anotherObject.message + ' ' + anotherObject.location);

you can learn more about javascript objects here: http://net.tutsplus.com/tutorials/javascript-ajax/the-basics-of-object-oriented-javascript/

Jimmery
  • 9,783
  • 25
  • 83
  • 157