Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

How to add the geometry to google maps from geojson(retrieved as json) for a specified condition using javascript

$
0
0

I have a array called place_names which holds some place names. I have a geojson layer loaded in my cartodb, which has three columns id, name and the_geom(which is a geometry object) that can be queried and retrieved as json. What i need is i am comparing the names in place_names array to the geojson name column, if the name in place_names array matches with that of geojson names, i want to retrieve the geometry of that matched names and add that to google maps.How this could be done?Below is my code.

var place_names = [];
$.getJSON(json_link,
    function (data) {
            for (i=0; i<data.rows.length; i++) {
                            unique = data.rows[i].region_name;
                            place_names.push(unique);
                        }
/*geojson names field*/
var msa_place = [];
$.getJSON(msa_usa_json_link,
  function (data) {
            for (i=0; i<data.rows.length; i++) {
                            msa_name = data.rows[i].name;
                            msa_place.push(msa_name);
                        }
                    });

var places = [];
    for (i=0; i<place_names.length; i++) {
        for (j=0; j<msa_place.length; j++) {

            if (place_names[i] === msa_place[j]) {
                places.push(place_names[i]);
                console.log(places);
                for (e=0; e<places.length; e++) {
                    ....../*do something to get geometry of matched places */
                }
            }
            else {
                console.log("no matches found");
            }

        }
    }
});

});


Viewing all articles
Browse latest Browse all 148

Trending Articles