I need to draw a polyline between two points using the shortest distance. Example, my location is New York, I have a location in China and I want to draw a polyline connecting t
Here's a working jsfiddle that answers the line problem. There is a method attached to the LatLng object called wrap that is supposed to help. I had to experiment a bit to get it work. I settled on
if (Math.abs(loc1.lng - loc2.lng) > 180) {
latlongs = [loc1.wrap(179, -179), loc2];
}
Unfortunately, as you can see, the marker for China isn't replicated. I added the worldCopyJump: true
option to the map object, but it doesn't fix that particular problem. Not sure how to fix that.
Edit: For posterity's sake, I forgot to mention that the reason it wasn't working before was because of the transition over the International Date Line.