javascript - Google Maps API directionsService.route different ...

文章推薦指數: 80 %
投票人數:10人

How do I get directionsService to display the route on the map ... Resultsfromthe2022DeveloperSurveyarehere. Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore GoogleMapsAPIdirectionsService.routedifferentfromGoogleMapsDirections AskQuestion Asked 6years,9monthsago Modified 1year,6monthsago Viewed 26ktimes 10 2 I'musingGoogleMapsJSAPItosearchfornearbyplaces,i.e.restaurantsbasedonmyLatLng: varrequest={ location:myLocation, rankBy:google.maps.places.RankBy.DISTANCE, types:['bar','cafe','food','liquor_store','lodging','meal_delivery','meal_takeaway','night_club','restaurant'], keyword:['bar','pub'] }; searchService.nearbySearch(request,callback); IgettheResultsArrayandwanttoshowdirectionstothefirstplacefromthearray: varrequest={ origin:myLocation, destination:bars[0].geometry.location, travelMode:google.maps.TravelMode.WALKING }; directionsService.route(request,function(response,status){ if(status==google.maps.DirectionsStatus.OK){ directionsDisplay.setDirections(response); directionsDisplay.setOptions({ suppressMarkers:true }); varmyRoute=response.routes[0].legs[0]; for(vari=0;i Share Follow editedDec18,2020at19:51 answeredSep15,2015at22:45 geocodezipgeocodezip 154k1313goldbadges208208silverbadges238238bronzebadges 0 Addacomment  |  3 Thanksforyouranswer@geocodezip,incasesomeoneelseneedsit: https://developers.google.com/maps/documentation/javascript/examples/overlay-symbol-dashed services.directions.set.route(request,function(response,status){ if(status==google.maps.DirectionsStatus.OK){ services.directions.display.setDirections(response); varmyRoute=response.routes[0].legs[0]; varlineSymbol={ path:'M0,-10,1', strokeOpacity:1, scale:4 }; varline=newgoogle.maps.Polyline({ path:[myRoute.steps[myRoute.steps.length-1].end_point,to.geometry.location], strokeOpacity:0, strokeColor:"#7d7d7d", icons:[{ icon:lineSymbol, offset:'0', repeat:'20px' }], map:map }); } }); Share Follow answeredOct2,2015at16:00 damianbdamianb 14111goldbadge11silverbadge55bronzebadges 0 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedjavascriptgoogle-mapsgoogle-maps-api-3directionsoraskyourownquestion. TheOverflowBlog ExpertsfromStripeandWaymoexplainhowtocraftgreatdocumentation(Ep.455) Askedandanswered:theresultsforthe2022Developersurveyarehere! FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Testingnewtrafficmanagementtool AskWizardTestResultsandNextSteps Trending:Anewanswersortingoption Linked -1 PreventMapsAPIfromgeocodingcoordinates 0 GMapsAPI-calcroutedrivingintopedestrianarea Related 7039 HowdoIremoveapropertyfromaJavaScriptobject? 441 GoogleMapsAPIv3:Howtoremoveallmarkers? 314 GoogleMapAPIv3—setboundsandcenter 2455 Getselectedtextfromadrop-downlist(selectbox)usingjQuery 569 HowtodisablemousescrollwheelscalingwithGoogleMapsAPI 3 GoogleMapsV3RouteDestinationMarkEdit 427 LaunchingGoogleMapsDirectionsviaanintentonAndroid 4348 WhydoesGoogleprependwhile(1);totheirJSONresponses? 706 GoogleMapsJSAPIv3-SimpleMultipleMarkerExample 10692 HowcanIremoveaspecificitemfromanarray? HotNetworkQuestions Thelongestpathofedgesona3x3grid Algorithmformergingarrayswhilekeepingtheirorder WhataretheregularlyspacedspotsonthispieceofmaterialonthesurfaceofMars? Howtallarethemushrooms? UsingCompileonGradientwithinFindMinimumefficiently InP.J.Plauger's"TheStandardCLibrary"(1992),whyareforloopsusedsofrequentlyinsteadofwhileloopsintheimplementations? Auto-Launchappfromthedmg Isacrylic/Perspexasuitablematerialforareplacementfridgeshelf? RouteMapping:Roadchoice Ifaplayercastsaspellofunlimiteddurationandretrainsoutofit,doesthespellremainactive? Whatdoes"ifinlocation"contextmeaninNginx? Kakeyacrossed-needlesproblem WouldpubliclyfartingonapictureoftheEnglishmonarchactuallyqualifyastreasonin1798? WhatisthepurposeofthefuelpumpsintheA320? WhathappenedtothelastworkGaunceLewiswasdoingwhenhedied? Whydidmybicyclehaveaspokeshatterandatuberupture? Operationalizingthedefinitionof"datingrelationship"infederalUSdomesticviolencelaw BestWaytoStyleRidiculouslyLongHair(formagicpurposes) GirlfriendtookoffwiththecarIgotaloanfor whydoesthedataisendtotheservergetroundedoffandhowdoisendtheentirefloatinstead StartupDiskCreatordoesnotexist Travelvisaappointment-Whatexactlyispassportphotocopy? DungeonWorld:Can1GMand2playerswork? Aremidi-chloriansstillcanon,despitenotbeingmentionedsinceEpisode1? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-js Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?