Select to view content in your preferred language

Get an attribute from a  json array and alert it

567
1
03-17-2013 09:28 AM
SaiDake
Emerging Contributor
I have a json array and im plotting an icon on the map by taking latitude and longitude from it. Now on click of that icon, i want that particular attributd to be alerted.

var locations3 = [{'latitude': 33.861269, 'longitude': -118.063548, 'address_id': 1, 'state': NY, 'address': null},
                         {'latitude': 33.858826,'longitude': -118.062749, 'address_id': 2, 'state': null, 'address': null},
                         {'latitude': 33.860903,'longitude': -118.062789, 'address_id': 3, 'state': null, 'address': null},
                         {'latitude': 33.861190,'longitude': -118.061151, 'address_id': 4, 'state': null, 'address': null},
                         {'latitude': 33.860534,'longitude': -118.06169, 'address_id': 5, 'state': null, 'address': null},
                         {'latitude': 33.860999,'longitude': -118.060164, 'address_id': 6, 'state': null, 'address': null}];

i have used dojo.foreach to plot latitude and logitude and drop an icon on the map. Onclick of the icon, i have an graphics event listener. Now, onclick of any particular icon, i want the corresponding address_id displayed (alerted).
0 Kudos
1 Reply
SaiDake
Emerging Contributor
var locations3 = [{'latitude': 33.861269, 'longitude': -118.063548, 'address_id': 1, 'state': NY, 'address': null},
{'latitude': 33.858826,'longitude': -118.062749, 'address_id': 2, 'state': null, 'address': null},
{'latitude': 33.860903,'longitude': -118.062789, 'address_id': 3, 'state': null, 'address': null},
{'latitude': 33.861190,'longitude': -118.061151, 'address_id': 4, 'state': null, 'address': null},
{'latitude': 33.860534,'longitude': -118.06169, 'address_id': 5, 'state': null, 'address': null},
{'latitude': 33.860999,'longitude': -118.060164, 'address_id': 6, 'state': null, 'address': null}];

dojo.forEach(locations3, function(location, i) {
              if (location.address_id != null && location.state != null) {
                plotAddressId(location.address_id, location.state);
              }



plotAddressId= function plotAddressId(addressId, state) {
            addressIdQuery = new esri.tasks.Query();
            addressIdQuery.returnGeometry = true;
            addressIdQuery.where = "ADDRESS_KEY = '" + state + addressId + "'";
            addressIdQueryTask.execute(addressIdQuery, function(results) {
              var geom = results.features[0].geometry;
              var graphic = new esri.Graphic(geom, locationSymbol);
              locationGraphicsLayer.add(graphic);
              zoomToLocations();
           });
          }
It renders everything on the map.  I need to get the corresponding latitude & longitude of the graphic clicked. Pls help!!
0 Kudos