开发者

Color markers on Google map using Javascript

Hello I'm new to rails in general.

I'm building a web application using rails in which I need to render different people locations using google map.

Basically I want to generate different color markers depending on user group. No开发者_StackOverflow社区w how do I do that processing in the javascript file?


You can use MapIconMaker Library for coloring markers, you can define many colors to manege your groups:

var GROUP_1 = MapIconMaker.createMarkerIcon({primaryColor: "#04b404"});
var GROUP_2 = MapIconMaker.createMarkerIcon({primaryColor: "#58acf4"});
var GROUP_3 = MapIconMaker.createMarkerIcon({primaryColor: "#ff8000"});

point = new GLatLng(latitude, longitude);
marker = new GMarker(point,{icon: GROUP_1});

Hope this helps


If I remember correctly, other than the default icon, you must use an image for the icon in other coloring scenarios as described here : http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerOptions

In an implementation I've used before, it looked similar to this:

                $.each(data, function() {
                  var post_position = new google.maps.LatLng(this.latitude, this.longitude);
                  var marker = new google.maps.Marker({
                    position: post_position,
                    map: map,
                    title: this.title,
                    icon: "images/purple_icon.png"
                });
                markerArray.push(marker);
            })


You can use gmaps4rails and customize your markers according to whatever rule you want.

See screencasts (I know res is poor but vote on Railscasts!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜