circle icon with different color based on the values in the data using google maps api

1,458 views
Skip to first unread message

Farook M

unread,
Nov 19, 2015, 5:33:57 AM11/19/15
to Google Maps JavaScript API v3

I am reading the place names from a database and doing geocoding using google maps api. I am using circle icons instead of default red markers. Now i would like to know whether those circle icon can be appear in different colours based on the value in the csv data using google maps api?

for ex i will get a json response for the region_name and average as

$.getJSON(json_link,
                            function (data) {
                                //console.log(data)
                                // response(data);
                                var place_names = [];
                                var average_value = [];
                                for (i=0; i<data.rows.length; i++) {
                                    unique = data.rows[i].region_name;
                                    place_names.push(unique);
                                }
                                for (i=0; i<data.rows.length; i++) {
                                    average_values = data.rows[i].average;
                                    average_value.push(average_values);
                                }
                                console.log(place_names);
                                console.log(average_value);

And those region_names will have corresponding average values which is stored in average_value array. For those particular region_names with their corresponding average_value, i should get the color of the circle icon vary.

And my geocoding part is

var address = place_names;
                                console.log(address);
                                for (i=0; i<=address.length; i++) {
                                    geocoder.geocode({'address': address[i]}, function(results, status) {
                                        if (status === google.maps.GeocoderStatus.OK) {
                                            map.setCenter(results[0].geometry.location);
                                            var marker = new google.maps.Marker({
                                                position: results[0].geometry.location,
                                                icon: {
                                                    path: google.maps.SymbolPath.CIRCLE,
                                                    scale: 10,
                                                    fillColor: "#F00",
                                                    fillOpacity: 0.4,
                                                    strokeWeight: 0.4
                                                },
                                                map: map
                                            });
                                            marker.setIcon({
                                                path: google.maps.SymbolPath.CIRCLE,
                                                scale: 10,
                                                fillColor: "#F00",
                                                fillOpacity: 0.5,
                                                strokeWeight: 1
                                            });

Mark McDonald

unread,
Nov 19, 2015, 4:21:57 PM11/19/15
to Google Maps JavaScript API v3

You might be able to adapt some of the code from this tutorial: https://developers.google.com/maps/articles/combining-data

In particular, the styling section, where fillColor is calculated.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-maps-js-a...@googlegroups.com.
To post to this group, send email to google-map...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.

Farook M

unread,
Nov 20, 2015, 1:51:50 AM11/20/15
to Google Maps JavaScript API v3
Thank you Mark McDonald. Seems to be useful.
Reply all
Reply to author
Forward
0 new messages