length of line

129 views
Skip to first unread message

bertaudmarc

unread,
May 19, 2011, 6:03:40 AM5/19/11
to Google Maps JavaScript API v3
Is it possible/easy to display under a line (build with polyline) its
length ?

geoco...@gmail.com

unread,
May 19, 2011, 8:01:55 AM5/19/11
to Google Maps JavaScript API v3
On May 19, 3:03 am, bertaudmarc <bertaudm...@gmail.com> wrote:
> Is it possible/easy to display under a line (build with polyline) its
> length ?

Yes.

1. calculate the length of the line (the geometry library should help)

Here is an example created before the geometry library existed:
http://www.geocodezip.com/v3_GenericMapBrowser.asp?filename=I5Polyline.xml

2. display it. Usually use an infowindow when the line is clicked,
but you can use the "infobox" library to create a label.

-- Larry

bertaudmarc

unread,
May 19, 2011, 10:15:49 AM5/19/11
to Google Maps JavaScript API v3
1) no problem for that
2) can the infobox-label stay visible when the line is moving ?


On 19 mai, 14:01, "geocode...@gmail.com" <geocode...@gmail.com> wrote:
> On May 19, 3:03 am, bertaudmarc <bertaudm...@gmail.com> wrote:
>
> > Is it possible/easy to display under a line (build with polyline) its
> > length ?
>
> Yes.
>
> 1. calculate the length of the line (the geometry library should help)
>
> Here is an example created before the geometry library existed:http://www.geocodezip.com/v3_GenericMapBrowser.asp?filename=I5Polylin...

geoco...@gmail.com

unread,
May 19, 2011, 11:00:53 AM5/19/11
to Google Maps JavaScript API v3
On May 19, 7:15 am, bertaudmarc <bertaudm...@gmail.com> wrote:
> 1) no problem for that
> 2) can the infobox-label stay visible when the line is moving ?

Probably. What is causing the line to move?

-- Larry

bertaudmarc

unread,
May 19, 2011, 1:14:34 PM5/19/11
to Google Maps JavaScript API v3
The first point of the line is the center of a circle, le second point
is draggable and will be the radius after clicking.
During the drag, I want to display the length of the line.

var ib;
var traceOptions = {
content: "000m",
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(-40, 0),
zIndex: null,
boxStyle: { border: "1px solid black", opacity: 0.75, width:
"40px" },
closeBoxMargin: "",
closeBoxURL: "",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: true
};
...
g.event.addListener(map, 'mousemove', function(event)
{ traceLine(event.latLng)});
...
function traceLine(point)
{
if (radius)
{
radius.setMap(null);
traceMarker.setMap(null);
ib.close();
}

radius= new g.Polyline({
path:[center,point],
strokeColor: "#000000",
strokeOpacity: 1.0,
strokeWeight: 1});
radius.setMap(map);

traceMarker = new g.Marker({
map: map,
draggable: true,
position: point,
visible: true
});

ib = new InfoBox(traceOptions);
lengthLine =
g.geometry.spherical.computeDistanceBetween(center,point);
ib.content = lengthLine.toString();
//ib.setPosition(); put the labelbox in the middle of the
line, later.
ib.open(map, traceMarker);
g.event.addListener(radius, 'click', function(event)
{fixRadius(event.latLng)});
}
...

geoco...@gmail.com

unread,
May 19, 2011, 3:27:54 PM5/19/11
to Google Maps JavaScript API v3
On May 19, 10:14 am, bertaudmarc <bertaudm...@gmail.com> wrote:
> The first point of the line is the center of a circle, le second point
> is draggable and will be the radius after clicking.
> During the drag, I want to display the length of the line.

Have you seen this:
http://code.google.com/apis/maps/articles/mvcfun/step6.html

From:
http://code.google.com/apis/maps/articles/mvcfun.html

(not quite what you are trying to do, but the same concept)

-- Larry

bertaudmarc

unread,
May 19, 2011, 5:38:17 PM5/19/11
to Google Maps JavaScript API v3
No, I discovered it. Same concept indeed.
But I am not sure I could display the length on the radius. In a
labelbox, yes, but not on the line(up or down AND in parallel).
Reply all
Reply to author
Forward
0 new messages