我正面临一个真正的问题,试图追踪一条连接点的路线,但要确保路线经过航路点并遵循线路边界。
我试着更具体一点。在下图中,在左侧我们可以看到一个绿点,这是我必须绘制的路线的起点。黄点是这条线的边界,我们可以称之为路径。在右边,我试图手动绘制我期望的结果。
对于上述情况,我几乎可以通过使用谷歌的方向服务来做到这一点,但结果是不正确的,因为有时它不会采取我想要的预期路线,即。不遵循边界。
这是另一个例子,因为有时路线可以分成两条路径。
这是我的代码,它显示停止点,方式点和尝试将点连接在一起。
如果有人能够通过遵循边界(黄点)将点连接在一起是个好主意,那将非常好,因为我已经花费了大量时间来寻找解决方案。 / p>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
#map-canvas {
height: 550px;
width: 550px;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
<script>
var boundary = [[4.398844 ,45.446252],[4.400346 ,45.446403],[4.400625 ,45.446403],[4.400625 ,45.446674],[4.400926 ,45.44696],[4.401333 ,45.447291],[4.401505 ,45.447622],[4.401591 ,45.447984],[4.401569 ,45.4483],[4.401612 ,45.448526],[4.401698 ,45.448526],[4.401698 ,45.448736],[4.401784 ,45.448992],[4.401891 ,45.449203],[4.401977 ,45.449414],[4.402235 ,45.449594],[4.402621 ,45.450467],[4.40187 ,45.450467],[4.40187 ,45.449594],[4.402621 ,45.449414],[4.402235 ,45.449203],[4.401977 ,45.449113],[4.401655 ,45.448872],[4.401248 ,45.448699],[4.400979 ,45.448699],[4.400979 ,45.448556],[4.400668 ,45.448134],[4.39996 ,45.447773],[4.399316 ,45.447562],[4.39893 ,45.447389],[4.398619 ,45.447389],[4.398619 ,45.447035],[4.397986 ,45.446674],[4.397986 ,45.445816],[4.398018 ,45.445816],[4.398018 ,45.444852],[4.398029 ,45.444626],[4.397814 ,45.44428],[4.397385 ,45.443994],[4.39717 ,45.443663],[4.39702 ,45.443452],[4.397042 ,45.443196],[4.397256 ,45.443076],[4.397385 ,45.44297],[4.39805 ,45.44285],[4.398758 ,45.44279],[4.399102 ,45.442715],[4.399649 ,45.442715],[4.399649 ,45.44279],[4.399102 ,45.442444],[4.398909 ,45.441811],[4.398587 ,45.441254],[4.399166 ,45.440802],[4.399617 ,45.440577],[4.39981 ,45.440306],[4.399853 ,45.44014],[4.399853 ,45.440035],[4.399359 ,45.439929],[4.398951 ,45.439884],[4.398651 ,45.439854],[4.398415 ,45.439749],[4.398136 ,45.439568],[4.397836 ,45.439252],[4.397492 ,45.438695],[4.396806 ,45.438476],[4.396527 ,45.438476],[4.396527 ,45.438288],[4.396291 ,45.437987],[4.395819 ,45.437761],[4.39554 ,45.43743],[4.395196 ,45.437189],[4.394853 ,45.437189],[4.394853 ,45.436587],[4.394059 ,45.436391],[4.39436 ,45.436195],[4.394531 ,45.435909],[4.394596 ,45.435653],[4.394617 ,45.435352],[4.394703 ,45.43493],[4.394853 ,45.434524],[4.395025 ,45.434117],[4.395175 ,45.433801],[4.395282 ,45.433545],[4.39539 ,45.433545],[4.39539 ,45.433214],[4.395518 ,45.432868],[4.395647 ,45.432536],[4.395776 ,45.432325],[4.395819 ,45.432145],[4.395733 ,45.431979],[4.395626 ,45.431813],[4.395475 ,45.431678],[4.395218 ,45.431271],[4.39554 ,45.431],[4.395754 ,45.430925],[4.396226 ,45.430925],[4.396226 ,45.430669],[4.397085 ,45.430413],[4.397621 ,45.430232],[4.397943 ,45.429961],[4.398372 ,45.429781],[4.398651 ,45.429464],[4.399166 ,45.429163],[4.39966 ,45.429028],[4.399939 ,45.428982],[4.400175 ,45.428998],[4.400411 ,45.428998],[4.400411 ,45.428982],[4.400175 ,45.429028],[4.399939 ,45.429163],[4.39966 ,45.429464],[4.399166 ,45.429781],[4.398651 ,45.429871],[4.398533 ,45.429871],[4.398533 ,45.429961],[4.398372 ,45.430232],[4.397943 ,45.430413],[4.397621 ,45.430669],[4.397085 ,45.431113],[4.39672 ,45.431113],[4.39672 ,45.431362],[4.39657 ,45.432009],[4.396291 ,45.432386],[4.396141 ,45.432717],[4.395969 ,45.432988],[4.395905 ,45.433199],[4.395776 ,45.433365],[4.395669 ,45.433545],[4.39539 ,45.433545],[4.39539 ,45.433801],[4.395282 ,45.434117],[4.395175 ,45.434524],[4.395025 ,45.43493],[4.394853 ,45.435352],[4.394703 ,45.435653],[4.394617 ,45.435909],[4.394596 ,45.436195],[4.394531 ,45.436391],[4.39436 ,45.436587],[4.394059 ,45.437355],[4.392922 ,45.437355],[4.392922 ,45.437505],[4.393308 ,45.437686],[4.393609 ,45.438032],[4.393995 ,45.438393],[4.394381 ,45.438755],[4.394789 ,45.438966],[4.395068 ,45.439086],[4.395239 ,45.439161],[4.395475 ,45.439222],[4.395669 ,45.439327],[4.396119 ,45.439402],[4.39642 ,45.43944],[4.396752 ,45.43944],[4.396752 ,45.439568],[4.397836 ,45.439749],[4.398136 ,45.439854],[4.398415 ,45.439884],[4.398651 ,45.439929],[4.398951 ,45.440035],[4.399359 ,45.44014],[4.399853 ,45.440396],[4.401119 ,45.440682],[4.400947 ,45.441149],[4.400668 ,45.4416],[4.400389 ,45.442052],[4.400175 ,45.442203],[4.400175 ,45.442338],[4.400175 ,45.442459],[4.400218 ,45.442579],[4.400303 ,45.442715],[4.399649 ,45.428757],[4.407513 ,45.428727],[4.407213 ,45.428546],[4.406054 ,45.428486],[4.405603 ,45.42841],[4.405174 ,45.428365],[4.404874 ,45.42841],[4.404573 ,45.428561],[4.403951 ,45.428621],[4.403672 ,45.428621],[4.403672 ,45.428561],[4.403951 ,45.42841],[4.404573 ,45.428365],[4.404874 ,45.42841],[4.405174 ,45.428486],[4.405603 ,45.428486],[4.405797 ,45.428486],[4.405797 ,45.428546],[4.406054 ,45.428727],[4.407213 ,45.428757],[4.407513 ,45.428757],[4.407513 ,45.428847],[4.407921 ,45.428982],[4.408779 ,45.429118],[4.409358 ,45.429269],[4.409745 ,45.429269],[4.409745 ,45.429058],[4.409745 ,45.428486],[4.409745 ,45.427657],[4.409766 ,45.427221],[4.409809 ,45.426874],[4.409809 ,45.426663],[4.409895 ,45.426663],[4.409895 ,45.426437],[4.409916 ,45.426136],[4.410067 ,45.425895],[4.410388 ,45.425745],[4.410732 ,45.425715],[4.411182 ,45.42576],[4.41159 ,45.42588],[4.411998 ,45.426001],[4.412363 ,45.426166],[4.412684 ,45.426302],[4.412942 ,45.426302],[4.412942 ,45.426453],[4.413178 ,45.426739],[4.413564 ,45.42701],[4.413757 ,45.427145],[4.413993 ,45.427205],[4.414272 ,45.427311],[4.414723 ,45.427461],[4.414937 ,45.427703],[4.415045 ,45.428215],[4.415367 ,45.428425],[4.415495 ,45.428425],[4.415495 ,45.42838],[4.415688 ,45.428019],[4.41659 ,45.427703],[4.417255 ,45.427386],[4.417856 ,45.427055],[4.418349 ,45.426965],[4.418521 ,45.426965],[4.418521 ,45.426874],[4.418628 ,45.426453],[4.419143 ,45.426106],[4.419551 ,45.425978],[4.41998 ,45.42579],[4.420645 ,45.425639],[4.421203 ,45.425489],[4.421611 ,45.425368],[4.421911 ,45.425157],[4.422169 ,45.425022],[4.422319 ,45.424841],[4.422534 ,45.424691],[4.422748 ,45.424691],[4.422748 ,45.42454],[4.423091 ,45.424314],[4.423542 ,45.424028],[4.424014 ,45.423787],[4.424357 ,45.423501],[4.424679 ,45.423245],[4.424937 ,45.423064],[4.425065 ,45.422868],[4.425173 ,45.422868],[4.425173 ,45.422627],[4.425302 ,45.42207],[4.425538 ,45.421573],[4.425709 ,45.421212],[4.425709 ,45.420775],[4.42558 ,45.420504],[4.425452 ,45.420293],[4.42528 ,45.420293],[4.42528 ,45.420187],[4.425194 ,45.419886],[4.424894 ,45.41966],[4.424529 ,45.419118],[4.423585 ,45.418968],[4.423327 ,45.41823],[4.422019 ,45.418164],[4.421827 ,45.452229],[4.399509 ,45.452063],[4.39981 ,45.451642],[4.400454 ,45.45125],[4.401033 ,45.450904],[4.401441 ,45.450753],[4.401612 ,45.450467],[4.40187 ,45.429269],[4.409745 ,45.429382],[4.409992 ,45.429374],[4.410399 ,45.429389],[4.411054 ,45.429351],[4.411697 ,45.429186],[4.412781 ,45.429035],[4.413596 ,45.428794],[4.414433 ,45.428576],[4.415141 ,45.428425],[4.415495 ,45.467836],[4.397492 ,45.467595],[4.397664 ,45.467279],[4.397793 ,45.467038],[4.39805 ,45.466775],[4.398415 ,45.466564],[4.398726 ,45.466421],[4.398887 ,45.466196],[4.398887 ,45.46591],[4.39893 ,45.465654],[4.39893 ,45.465428],[4.398887 ,45.465428],[4.398887 ,45.465052],[4.398801 ,45.464766],[4.39863 ,45.464405],[4.398394 ,45.464029],[4.398222 ,45.463592],[4.398007 ,45.463261],[4.397857 ,45.463261],[4.397857 ,45.46278],[4.397643 ,45.462027],[4.397278 ,45.46153],[4.397042 ,45.461275],[4.396935 ,45.460988],[4.396827 ,45.460988],[4.396827 ,45.460597],[4.396634 ,45.460371],[4.396484 ,45.46001],[4.396291 ,45.459634],[4.396162 ,45.459453],[4.396076 ,45.459198],[4.39584 ,45.458776],[4.395347 ,45.458535],[4.395068 ,45.458535],[4.395068 ,45.458264],[4.394724 ,45.458039],[4.39436 ,45.457843],[4.394038 ,45.457617],[4.393673 ,45.457467],[4.393394 ,45.457467],[4.393394 ,45.457301],[4.393072 ,45.457015],[4.392643 ,45.456759],[4.392343 ,45.456383],[4.392021 ,45.455976],[4.391763 ,45.455555],[4.391549 ,45.454998],[4.391313 ,45.454381],[4.391012 ,45.45402],[4.390883 ,45.45402],[4.390883 ,45.453568],[4.390701 ,45.453553],[4.391205 ,45.453628],[4.391881 ,45.453734],[4.392471 ,45.453869],[4.393158 ,45.45399],[4.393866 ,45.45405],[4.394467 ,45.45405],[4.394467 ,45.45411],[4.395132 ,45.454163],[4.396699 ,45.4542],[4.39717 ,45.45414],[4.397514 ,45.454005],[4.397943 ,45.453689],[4.398694 ,45.453523],[4.399016 ,45.453523],[4.399016 ,45.453282],[4.398909 ,45.453056],[4.398823 ,45.45268],[4.39878 ,45.45256],[4.399016 ,45.452424],[4.399273 ,45.452229],[4.399509 ,45.472531],[4.399102 ,45.47214],[4.399359 ,45.471342],[4.399724 ,45.471026],[4.39996 ,45.47077],[4.400346 ,45.471011],[4.400711 ,45.471583],[4.401527 ,45.472004],[4.40217 ,45.471703],[4.402642 ,45.471523],[4.402835 ,45.471523],[4.402835 ,45.471703],[4.402642 ,45.472004],[4.40217 ,45.471583],[4.401527 ,45.471011],[4.400711 ,45.47077],[4.400346 ,45.470913],[4.40011 ,45.470913],[4.40011 ,45.471026],[4.39996 ,45.471342],[4.399724 ,45.47214],[4.399359 ,45.472531],[4.399102 ,45.472531],[4.399102 ,45.472877],[4.39893 ,45.473449],[4.398673 ,45.47399],[4.398565 ,45.474487],[4.398436 ,45.474788],[4.398254 ,45.474916],[4.398018 ,45.474969],[4.397643 ,45.474863],[4.397224 ,45.474683],[4.396999 ,45.474336],[4.396784 ,45.473855],[4.396527 ,45.473163],[4.396226 ,45.47279],[4.396143 ,45.47279],[4.396143 ,45.472456],[4.396076 ,45.471778],[4.395948 ,45.471162],[4.395797 ,45.470695],[4.395754 ,45.470274],[4.395754 ,45.470274],[4.395754 ,45.469898],[4.395776 ,45.469416],[4.395948 ,45.468965],[4.396205 ,45.468679],[4.396462 ,45.468453],[4.396741 ,45.468242],[4.397042 ,45.468062],[4.397299 ,45.467836],[4.397492 ,45.428998],[4.400411 ,45.428975],[4.40084 ,45.428967],[4.402084 ,45.428967],[4.402342 ,45.428877],[4.402707 ,45.428711],[4.40335 ,45.428621],[4.403672 ,45.445266]];
var points = [
['4', '3', '45.426663388885', '4.4098949432373', '43, Le Corbusier', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['5', '3', '45.426301960728', '4.4129419326782', '57, Le Corbusier', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['160', '3', '45.429261085673', '4.4097447395325', 'Beaulieu', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['477', '3', '45.428417788517', '4.4155061244965', 'Centre Commercial Montchovet', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['1030', '3', '45.422868277819', '4.4251728057861', 'Faculté des Sciences', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['1772', '3', '45.424690565371', '4.4227588176727', 'L\'Angélus', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['1785', '3', '45.429870962373', '4.3985331058502', 'Lassaigne', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['2371', '3', '45.428485553932', '4.4057965278625', 'Liogier', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['2396', '3', '45.428621084519', '4.4036722183228', 'Louis Blanc', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['2563', '3', '45.426964577248', '4.4185209274292', 'Marandinière', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['2713', '3', '45.42029287858', '4.4252908229828', 'Nicolas Mignard', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['2829', '3', '45.428749085331', '4.4075131416321', 'Pierre Blachon', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['3167', '3', '45.428997556665', '4.4004213809967', 'Résidence Guinard', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['34356', '3', '45.452228557408', '4.3995094299316', 'AFPA', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['34997', '3', '45.438476297658', '4.3965268135071', 'Chantegrillet', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35202', '3', '45.467835981334', '4.3974924087524', 'Claudius Petit', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35318', '3', '45.446402886221', '4.4006252288818', 'Collège Vallès', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35341', '3', '45.430925054711', '4.3962264060974', 'Conservatoire', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35478', '3', '45.472523384943', '4.3991017341614', 'Debussy', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35728', '3', '45.43943989305', '4.3967521190643', 'Fourneyron', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['35936', '3', '45.470905785694', '4.400110244751', 'Georges Bizet', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['36075', '3', '45.46542817465', '4.3988978862762', 'Gustave Delory', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['36246', '3', '45.437354591671', '4.3929219245911', 'Jean Moulin', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['36700', '3', '45.460980986303', '4.3968272209167', 'Le Bessard', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['36806', '3', '45.458535259453', '4.395078420639', 'Le Marais', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['37262', '3', '45.445815769704', '4.3980181217194', 'Louis Soulié', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['37264', '3', '45.445258756078', '4.3988442420959', 'Louis Soulié', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['37309', '3', '45.437188968764', '4.3948531150818', 'Lycée Fauriel', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['37722', '3', '45.472786710659', '4.396151304245', 'Offenbach', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38016', '3', '45.44869107689', '4.4009900093079', 'Place Dumay', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38019', '3', '45.448525487259', '4.4016981124878', 'Place Dumay', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38054', '3', '45.433537612998', '4.3954002857208', 'Place Villeboeuf', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38240', '3', '45.457459106031', '4.3934047222137', 'Productique', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38508', '3', '45.454019792709', '4.3908834457397', 'Rue des Acieries', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38537', '3', '45.431113283414', '4.3967199325562', 'Rue Emile', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38755', '3', '45.453523069292', '4.3990159034729', 'Scheurer Kestner', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38793', '3', '45.450467371436', '4.4018805027008', 'Soleil', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['38917', '3', '45.447381400169', '4.3986189365387', 'Tiblier Verne', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['39041', '3', '45.4632610607', '4.3978679180145', 'Victor Grignard', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['39078', '3', '45.470273780817', '4.3957543373108', 'Vivaldi', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538'],
['39108', '3', '45.454049897017', '4.3944776058197', 'Zénith', '3', 'STAS-9:9', '', '1', '3', '3', 'Saint-Étienne', '42000', '4.3924', '45.4538']
];
var stops = [
[ 45.442669323228, 4.3996810913086, "Ch\u00e2teaucreux" ],
[ 45.418093906726, 4.4219970703125, "M\u00e9tare" ],
[ 45.47144749852, 4.4029426574707, "Montreynaud" ]
];
var directionsDisplay = [];
var directionsService = [];
function drawRouteMap(map,locations) {
var start, end;
var waypts = [];
for (var k = 0; k < locations.length; k++) {
if (k >= 1 && k <= locations.length - 2) {
waypts.push({
location: locations[k],
stopover: false
});
}
if (k == 0) start = locations[k];
if (k == locations.length - 1) end = locations[k];
}
var request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: false,
travelMode: google.maps.TravelMode.DRIVING
};
console.log(request);
directionsService.push(new google.maps.DirectionsService());
var instance = directionsService.length - 1;
directionsDisplay.push(new google.maps.DirectionsRenderer({
preserveViewport: true
}));
directionsDisplay[instance].setMap(map);
directionsService[instance].route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
console.log(status);
directionsDisplay[instance].setDirections(response);
}
});
}
function initialize() {
var mapOptions = {
zoom: 17,
center: new google.maps.LatLng(43.64686, 3.873507),
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
stop1 = new google.maps.Marker({
position: new google.maps.LatLng(stops[0][0], stops[0][1]),
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5.5,
fillColor: "green",
fillOpacity: 1,
strokeWeight: 0.4
},
title: stops[0][2]
});
stop2 = new google.maps.Marker({
position: new google.maps.LatLng(stops[1][0], stops[1][1]),
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5.5,
fillColor: "green",
fillOpacity: 1,
strokeWeight: 0.4
},
title: stops[1][2]
});
stop3 = new google.maps.Marker({
position: new google.maps.LatLng(stops[2][0], stops[2][1]),
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5.5,
fillColor: "green",
fillOpacity: 1,
strokeWeight: 0.4
},
title: stops[2][2]
});
var shape = {
coord: [1, 1, 1, 20, 18, 20, 18 , 1],
type: 'poly'
};
// Create a renderer for directions and bind it to the map.
var rendererOptions = {
map: map,
suppressMarkers: true
}
// Display the line bounds
for(var i = 0; i < boundary.length; i++) {
var myLatLon = new google.maps.LatLng(boundary[i][1], boundary[i][0]);
marker = new google.maps.Marker({
position: myLatLon,
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5.5,
fillColor: "yellow",
fillOpacity: 1,
strokeWeight: 0.4
},
title: ""
});
}
//Map bounds
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow(), marker, i;
var locations = new Array();
//Displaying stops
for(var i = 0; i < points.length; i++) {
console.log(points[i][2] + ',' + points[i][3]);
var myLatLon = new google.maps.LatLng(points[i][2], points[i][3]);
locations.push(myLatLon);
marker = new google.maps.Marker({
position: myLatLon,
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 5.5,
fillColor: "#F00",
fillOpacity: 1,
strokeWeight: 0.4
},
title: points[i][4]
});
bounds.extend(myLatLon);
}
map.fitBounds(bounds);
//Trying to connect all those points
var i = locations.length;
var index = 0;
while (i != 0) {
if ( i < 2) {
console.log("before :i < 2: i value " + i + " index value" + index);
var tmp_locations = new Array();
for (var j = index; j < locations.length; j++) {
tmp_locations.push(locations[j]);
}
drawRouteMap(map,tmp_locations);
i = 0;
index = locations.length;
console.log("after fun < 10: i value " + i + " index value" + index);
}
if (i >= 2) {
console.log("before :i >= 2: i value " + i + " index value" + index);
var tmp_locations = new Array();
for (var j = index; j < index + 2; j++) {
tmp_locations.push(locations[j]);
}
drawRouteMap(map,tmp_locations);
i = i - 1;
index = index + 1;
console.log("after i >= 2: i value " + i + " index value" + index);
}
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
<div id="map-warn"></div>
</body>
</html>