0

I can better explain my case by code snippet

var cascadiaFault = new google.maps.Polyline({
    paths: [
      new google.maps.LatLng(49.95, -128.1),
      new google.maps.LatLng(46.26, -126.3),
      new google.maps.LatLng(40.3, -125.4)
    ]
});

the value of paths property should be assigned from external variable pathsTemp

var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
	var bounds = boxes[i];
	// Perform search over this bounds
	pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
	paths: pathsTemp;
});

Its not working..

Other options that I tried

paths = pathsTemp; -- Not working
paths: paths.push(pathsTmep) -- No syntactic error but, uncaught reference error at runtime when this line is reached

PS: I don't have javascript background and unfortunately I don't have time to start reading the syntax and rules from scratch (However, I can understand most of the js code already written)

9
  • Your second approach looks fine, are you sure pathsTemp is the correct array? (what does getCenter return? a new LatLng object?) Commented Jul 1, 2015 at 8:50
  • boxes[i] is of type google.maps.LatLngBounds.. bounds.getCenter() returns object of type google.maps.LatLng Commented Jul 1, 2015 at 9:00
  • @doldt you are right Commented Jul 1, 2015 at 9:01
  • a google.maps.PolylineOptions doesn't have a paths property. It only has a path (paths is for Polygons) Commented Jul 1, 2015 at 13:49
  • @geocodezip the sample presented here uses paths developers.google.com/maps/documentation/javascript/… Commented Jul 1, 2015 at 22:32

2 Answers 2

1

Well, I got what the problem is

  1. The correct syntax is paths: pathsTemp

var pathsTemp = [];
for (var i = 0; i < boxes.length; i++) {
 	var bounds = boxes[i];
  	// Perform search over this bounds
   	pathsTemp.push(bounds.getCenter());
}
var cascadiaFault = new google.maps.Polyline({
   	paths: pathsTemp
});

  1. The above code is syntactically correct, but the problem is it should be path instead of paths

Though the sample example presented at https://developers.google.com/maps/documentation/javascript/geometry#isLocationOnEdge

uses paths, it works with path for me. May be a typo in API documentation

As expected, documentation bug logged

with reference to this stackoverflow discussion

Sign up to request clarification or add additional context in comments.

Comments

0

for the person who down voted the question : please take a look at this misleading example snippet from google documentation and change your opinion if it makes sense to you (Reputation matters a lot here, for a beginner like me)

enter image description here

7 Comments

OK. I stand corrected. That example is wrong (you will note that there isn't a live version of that one...)
@geocodezip Yeah thats what. I have looked carefully before posting, coz I don't want to lose reputation unnecessarily.
Working version of that example with path and a google.maps.Polyline. [Broken example[(jsfiddle.net/f1wqyh69/1) with paths (no polyline appears and no alert)
@geocodezip, I got that yesterday, thanks!!! If you have some time, can you please take a look at this old question and suggest something. Not sure you got notified
Merge this into your other answer. No need for two posts.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.