开发者

Google Maps API v3: Labelling a circle

开发者 https://www.devze.com 2023-01-14 23:11 出处:网络
I\'m using the following code to generate a circle on a map using the Google Maps v3 API: 开发者_开发问答

I'm using the following code to generate a circle on a map using the Google Maps v3 API:

开发者_开发问答
var postcode_a = new google.maps.Circle({
 center: postcode_a_location,
 map: map,
 radius: 70,
 fillColor: "#3da5e1",
 fillOpacity: 0.5,
 strokeColor: "#2b546b",
 strokeWeight: 1
});

What I would like to do is place a text label in the centre of my circle.

I have poured over the documentation and can see no easy way to do this. The only solution I can propose to myself is to overlay a marker on top of the circle and set the icon to a transparent PNG containing the text label I want to display. However, this is a pretty inelegant solution since I cannot accurately offset the position of the icon so that it displays in the centre of the circle at any zoom level (and for the other obvious reasons).

Can anyone suggest a solution to this? I am not above manipulating the API with a third party library. I have seen some written for v2 of the API, but most of these seem to be geared toward adding a label or tooltip to a marker rather than a circle, in any case.


How about you put an image overlay as it is described in the overlays section of the javascript sports documentation?

Also take a look at this

0

精彩评论

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