Drawing polyline error

115 views
Skip to first unread message

Rick M

unread,
Jun 13, 2011, 3:42:06 PM6/13/11
to google-map...@googlegroups.com
Hey everyone,
 
So I am just starting to familiarze myself with the Google Maps API and I am seeing an error while attempting to draw a polyline on a map.
 
I am working with my own version of the "Hello World" example provided in the tutorial. I receive an error stating "htmlfile: Unexpected call to method or property access" while attempting to push a second pair of coordinates to the polyLine MVC array. The code I am working with is below:
 

poly =

new google.maps.Polyline(polyOptions);

poly.setMap(basemap);

google.maps.event.addListener(basemap,

'click', drawLine);

 

function drawLine(event){

var newpath = poly.getPath();

newpath.push(event.latLng);

// <= Exception thrown at this line

newestmarker =

new google.maps.Marker({

position: event.latLng,

title:

'#' + newpath.getLength(),

map: basemap

});

}

Does anyone have any ideas as to what I might be missing? I've searched the forum and could not find any other cases of this exception being thrown. Thanks!

Rick

 

Ben

unread,
Jun 13, 2011, 9:21:28 PM6/13/11
to Google Maps JavaScript API v3
Not a javascript expert but..

google.maps.event.addListener(basemap, 'click', drawLine);

might need to be

google.maps.event.addListener(basemap, 'click', drawLine(event));

??

or I could be totally off.

On Jun 13, 3:42 pm, Rick M <rick.martell...@gmail.com> wrote:
> Hey everyone,
>
> So I am just starting to familiarze myself with the Google Maps API and I am
> seeing an error while attempting to draw a polyline on a map.
>
> I am working with my own version of the "Hello World" example provided in
> the tutorial. I receive an error stating *"htmlfile: Unexpected call to
> method or property access"* while attempting to push a second pair of

Luke Mahé

unread,
Jun 13, 2011, 9:52:54 PM6/13/11
to google-map...@googlegroups.com
Can you include a link to you page please.

-- Luke


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/dOV6ETcn4z4J.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Rick M

unread,
Jun 17, 2011, 4:51:24 PM6/17/11
to google-map...@googlegroups.com
Is the presence of an API key required when trying to reference the 'polyline' class of the Google API? If so, I believe that may be my problem.
 
Also, I run into issues when using my key and trying to debug locally. The key was issued for v2. Do I need to obtain a new key?
 
I realize these questions are not code related, so I can create a new topic and post there if necessary. Thanks!
 
Rick 

Jeremy Geerdes

unread,
Jun 17, 2011, 4:53:08 PM6/17/11
to google-map...@googlegroups.com
v3 does not use keys.

Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

For more information or a project quote:

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

Rick M

unread,
Jun 21, 2011, 10:59:25 AM6/21/11
to google-map...@googlegroups.com
Below is a link to the page. I'm just getting started with the API, so please excuse the rudimentary design. I am trying to draw a line by clicking on two points on the map. I've also noticed that the map only displays in certain browsers. Feel free to check out the full page source code. Thanks!


Rick

Rossko

unread,
Jun 21, 2011, 3:16:21 PM6/21/11
to Google Maps JavaScript API v3
> http://wa.efirstsearch.com/GoogleMaps/LocateTargetSite3.aspx

I just get a blank map in FF2. For some reason you're trying to put
your map in an <iframe> tag ; that's not what iframes are for. Just
try an ordinary <div>

So, I can't see your poly error. I'd imagine it's to do with getPath
not returning an array when there is no path yet, so your 'push' fails
on a non-array.

Rick M

unread,
Jun 21, 2011, 3:57:51 PM6/21/11
to google-map...@googlegroups.com
Problem solved! You're right, the <iframe> tag was completely unnecessary. Embedding the map into a normal <div> frame resolved the problem. The map will load in any browser and I can now successfully draw polylines. And for whatever reason the array path cannot be retrieved when the map is embedded in an iframe. Thanks so much for your help!

Rick
Reply all
Reply to author
Forward
0 new messages