How to add the geometry to google maps from geojson for a specified condition using javascript

32 views
Skip to first unread message

Farook M

unread,
Nov 24, 2015, 5:49:48 AM11/24/15
to Google Maps JavaScript API v3

I have two datasets loaded in a database, one is a geojson and other is a csv file. Both can be retrieved and return to as in json format.geojson has a field named "name" and csv has a field named "region_name". Both are stored in an array as below.

/*csv field*/
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 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);
                            }
                        });

What i want is i need to check whether the value in the place_name array is in msa_place array and if the condition satisfies, i should get the geometry of the matched value from the geojson (retrieved as json) and add the matched features alone to the google maps. The place names matched in both arrays are stored in a array called "places". For place names in places array, i want to get the geometry from geojson and add the geometry of that place alone to google maps.How this can be done? Below is my code.

    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);
        }

        console.log(place_names);
        console.log(msa_place);
        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");
                }

            }
        }
    });
});

What should i need to do to add the geometry of the matched features to google maps using googlemaps api?

Reply all
Reply to author
Forward
0 new messages