Directions | Maps JavaScript API - Google Developers

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

Returns the current (zero-based) route index in use by this DirectionsRenderer object. setDirections. setDirections(directions). Parameters: directions : ... Google MapsPlatform Overview Products Pricing Documentation GetStarted GetStartedwithGoogleMapsPlatform APIPicker Billing&Pricing Reporting&Monitoring MapIDs FAQ SupportandResources IncidentManagement Maps MapsJavaScriptAPI MapsSDKforAndroid MapsSDKforiOS MapsStaticAPI StreetViewStaticAPI MapsEmbedAPI MapsURLs MapsElevationAPI Routes DirectionsAPI DistanceMatrixAPI RoadsAPI Solutions IndustrySolutions GamingServices TransportationandLogistics Places PlacesAPI PlacesSDKforAndroid PlacesSDKforiOS PlacesLibrary,MapsJavaScriptAPI GeocodingAPI GeolocationAPI TimeZoneAPI AdditionalResources APISecurityBestPractices MapCoverageDetails OptimizationGuide MobileOSandsoftwaresupport Launchstages Deprecations AssetTrackingPlan URLEncoding WordPressUsers Blog Community StackOverflow GitHub YouTube Discord Twitter IssueTracker English BahasaIndonesia Deutsch Español Español–AméricaLatina Français Italiano Polski Português–Brasil TiếngViệt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文–简体 中文–繁體 日本語 한국어 Signin Web MapsJavaScriptAPI GetStarted Contactsales Guides Reference Samples Support Google MapsPlatform Overview Products Pricing Documentation More Guides Reference Samples Support Blog Community More APIReferencev3.50(weeklychannel) Overview GlobalConcepts google.mapsSettings(beta)EventsystemErrors Maps MapsWebGLCoordinatesData-drivenstyling(beta)ControlsGeometryLibrary Drawingonthemap MarkerInfoWindowPolygonsDataDOMelementsKMLImageoverlaysDrawingLibraryHeatmapsMaxZoom StreetView RenderingService Places PlacesWidgetsPlacesServicePlacesAutocompleteServiceGeocoder Routes DirectionsDistanceMatrixElevation LocalContext(beta) MapView JourneySharing(beta) MapViewAuthenticationUICustomizationFleetEngineEntitiesTripandOrderProgressFleetTrackingShipmentTracking APIReferencev3.49(quarterlychannel) Overview GlobalConcepts google.mapsSettings(beta)Errors Maps MapsWebGLCoordinatesData-drivenstylingEventsystemControlsGeometryLibrary Drawingonthemap MarkerInfoWindowPolygonsDataDOMelementsKMLImageoverlaysDrawingLibraryHeatmapsMaxZoom StreetView RenderingService Places PlacesWidgetsPlacesServicePlacesAutocompleteServiceGeocoder Routes DirectionsDistanceMatrixElevation LocalContext(beta) MapView JourneySharing(beta) MapViewAuthenticationUICustomizationFleetEngineEntitiesTripandOrderProgressFleetTrackingShipmentTracking APIReferencev3.48 Overview Maps MapsWebGLCoordinatesEventsystemControlsGeometryLibrary Drawingonthemap MarkerInfoWindowPolygonsDataDOMelementsKMLImageoverlaysDrawingLibraryHeatmapsMaxZoom StreetView RenderingService Places PlacesWidgetsPlacesServicePlacesAutocompleteServiceGeocoder Routes DirectionsDistanceMatrixElevation LocalContext(beta) MapView JourneySharing(beta) MapViewAuthenticationUICustomizationFleetEngineEntitiesTripandOrderProgressFleetTrackingShipmentTracking GlobalConfiguration(beta) Settings APIReferencev3.47 Overview Maps MapsWebGL(Beta)CoordinatesEventsystemControlsGeometryLibrary Drawingonthemap MarkerInfoWindowPolygonsDataDOMelementsKMLImageoverlaysDrawingLibraryHeatmapsMaxZoom StreetView RenderingService Places PlacesWidgetsPlacesServicePlacesAutocompleteServiceGeocoder Routes DirectionsDistanceMatrixElevation LocalContext(beta) MapView GetStarted GetStartedwithGoogleMapsPlatform APIPicker Billing&Pricing Reporting&Monitoring MapIDs FAQ SupportandResources IncidentManagement Maps MapsJavaScriptAPI MapsSDKforAndroid MapsSDKforiOS MapsStaticAPI StreetViewStaticAPI MapsEmbedAPI MapsURLs MapsElevationAPI Routes DirectionsAPI DistanceMatrixAPI RoadsAPI Solutions IndustrySolutions GamingServices TransportationandLogistics Places PlacesAPI PlacesSDKforAndroid PlacesSDKforiOS PlacesLibrary,MapsJavaScriptAPI GeocodingAPI GeolocationAPI TimeZoneAPI AdditionalResources APISecurityBestPractices MapCoverageDetails OptimizationGuide MobileOSandsoftwaresupport Launchstages Deprecations AssetTrackingPlan URLEncoding WordPressUsers StackOverflow GitHub YouTube Discord Twitter IssueTracker Home Products GoogleMapsPlatform Documentation Web MapsJavaScriptAPI Reference Sendfeedback Directions Stayorganizedwithcollections Saveandcategorizecontentbasedonyourpreferences. DirectionsService class google.maps.DirectionsService class Aserviceforcomputingdirectionsbetweentwoormoreplaces. Constructor DirectionsService DirectionsService() Parameters: None CreatesanewinstanceofaDirectionsServicethatsendsdirectionsqueriestoGoogleservers. Methods route route(request[,callback]) Parameters:  request: DirectionsRequest callback: function(DirectionsResultoptional,DirectionsStatus):voidoptional ReturnValue: Promise Issueadirectionssearchrequest. DirectionsRequest interface google.maps.DirectionsRequest interface AdirectionsquerytobesenttotheDirectionsService. Properties destination Type: string|LatLng|Place|LatLngLiteral Locationofdestination.Thiscanbespecifiedaseitherastringtobegeocoded,oraLatLng,oraPlace.Required. origin Type: string|LatLng|Place|LatLngLiteral Locationoforigin.Thiscanbespecifiedaseitherastringtobegeocoded,oraLatLng,oraPlace.Required. travelMode Type: TravelMode Typeofroutingrequested.Required. avoidFerriesoptional Type: booleanoptional Iftrue,instructstheDirectionsservicetoavoidferrieswherepossible.Optional. avoidHighwaysoptional Type: booleanoptional Iftrue,instructstheDirectionsservicetoavoidhighwayswherepossible.Optional. avoidTollsoptional Type: booleanoptional Iftrue,instructstheDirectionsservicetoavoidtollroadswherepossible.Optional. drivingOptionsoptional Type: DrivingOptionsoptional SettingsthatapplyonlytorequestswheretravelModeisDRIVING.Thisobjectwillhavenoeffectforothertravelmodes. languageoptional Notice:Availableonlyinthev=betachannel.Type: stringoptional Alanguageidentifierforthelanguageinwhichresultsshouldbereturned,whenpossible.Seethelistofsupportedlanguages. optimizeWaypointsoptional Type: booleanoptional Ifsettotrue,theDirectionsServicewillattempttore-orderthesuppliedintermediatewaypointstominimizeoverallcostoftheroute.Ifwaypointsareoptimized,inspectDirectionsRoute.waypoint_orderintheresponsetodeterminethenewordering. provideRouteAlternativesoptional Type: booleanoptional Whetherornotroutealternativesshouldbeprovided.Optional. regionoptional Type: stringoptional Regioncodeusedasabiasforgeocodingrequests.TheregioncodeacceptsaccTLD("top-leveldomain")two-charactervalue.MostccTLDcodesareidenticaltoISO3166-1codes,withsomenotableexceptions.Forexample,theUnitedKingdom'sccTLDis"uk"(.co.uk)whileitsISO3166-1codeis"gb"(technicallyfortheentityof"TheUnitedKingdomofGreatBritainandNorthernIreland"). transitOptionsoptional Type: TransitOptionsoptional SettingsthatapplyonlytorequestswheretravelModeisTRANSIT.Thisobjectwillhavenoeffectforothertravelmodes. unitSystemoptional Type: UnitSystemoptional Default:Theunitsystemusedinthecountryoforigin. Preferredunitsystemtousewhendisplayingdistance. waypointsoptional Type: Arrayoptional Arrayofintermediatewaypoints.Directionsarecalculatedfromtheorigintothedestinationbywayofeachwaypointinthisarray.Seethedeveloper'sguideforthemaximumnumberofwaypointsallowed.Waypointsarenotsupportedfortransitdirections.Optional. DirectionsStatus constants google.maps.DirectionsStatus constants ThestatusreturnedbytheDirectionsServiceonthecompletionofacalltoroute().Specifythesebyvalue,orbyusingtheconstant'sname.Forexample,'OK'orgoogle.maps.DirectionsStatus.OK. Constants INVALID_REQUEST TheDirectionsRequestprovidedwasinvalid. MAX_WAYPOINTS_EXCEEDED ToomanyDirectionsWaypointswereprovidedintheDirectionsRequest.Seethedeveloper'sguideforthemaximumnumberofwaypointsallowed. NOT_FOUND Atleastoneoftheorigin,destination,orwaypointscouldnotbegeocoded. OK TheresponsecontainsavalidDirectionsResult. OVER_QUERY_LIMIT Thewebpagehasgoneovertherequestslimitintooshortaperiodoftime. REQUEST_DENIED Thewebpageisnotallowedtousethedirectionsservice. UNKNOWN_ERROR Adirectionsrequestcouldnotbeprocessedduetoaservererror.Therequestmaysucceedifyoutryagain. ZERO_RESULTS Noroutecouldbefoundbetweentheoriginanddestination. DirectionsResult interface google.maps.DirectionsResult interface Thedirectionsresponseretrievedfromthedirectionsserver.YoucanrendertheseusingaDirectionsRendererorparsethisobjectandrenderityourself.YoumustdisplaythewarningsandcopyrightsasnotedintheGoogleMapsPlatformTermsofService.Notethatthoughthisresultis"JSON-like,"itisnotstrictlyJSON,asitindirectlyincludesLatLngobjects. Properties routes Type: Array AnarrayofDirectionsRoutes,eachofwhichcontainsinformationaboutthelegsandstepsofwhichitiscomposed.TherewillonlybeonerouteunlesstheDirectionsRequestwasmadewithprovideRouteAlternativessettotrue. available_travel_modesoptional Type: Arrayoptional Containsanarrayofavailabletravelmodes.Thisfieldisreturnedwhenarequestspecifiesatravelmodeandgetsnoresults.Thearraycontainstheavailabletravelmodesinthecountriesofthegivensetofwaypoints.Thisfieldisnotreturnedifoneormoreofthewaypointsare'viawaypoints'. geocoded_waypointsoptional Type: Arrayoptional AnarrayofDirectionsGeocodedWaypoints,eachofwhichcontainsinformationaboutthegeocodingoforigin,destinationandwaypoints. DirectionsRenderer class google.maps.DirectionsRenderer class RendersdirectionsobtainedfromtheDirectionsService. Thisclassextends MVCObject. Constructor DirectionsRenderer DirectionsRenderer([opts]) Parameters:  opts: DirectionsRendererOptionsoptional Createstherendererwiththegivenoptions.Directionscanberenderedonamap(asvisualoverlays)oradditionallyona

panel(astextualinstructions). Methods getDirections getDirections() Parameters: None ReturnValue: DirectionsResult Returnstherenderer'scurrentsetofdirections. getMap getMap() Parameters: None ReturnValue: Map ReturnsthemaponwhichtheDirectionsResultisrendered. getPanel getPanel() Parameters: None ReturnValue: HTMLElement|null Returnsthepanel
inwhichtheDirectionsResultisrendered. getRouteIndex getRouteIndex() Parameters: None ReturnValue: number Returnsthecurrent(zero-based)routeindexinusebythisDirectionsRendererobject. setDirections setDirections(directions) Parameters:  directions: DirectionsResult ReturnValue: None SettherenderertousetheresultfromtheDirectionsService.Settingavalidsetofdirectionsinthismannerwilldisplaythedirectionsontherenderer'sdesignatedmapandpanel. setMap setMap(map) Parameters:  map: Map ReturnValue: None Thismethodspecifiesthemaponwhichdirectionswillberendered.Passnulltoremovethedirectionsfromthemap. setOptions setOptions(options) Parameters:  options: DirectionsRendererOptions ReturnValue: None ChangetheoptionssettingsofthisDirectionsRendererafterinitialization. setPanel setPanel(panel) Parameters:  panel: HTMLElementoptional ReturnValue: None Thismethodrendersthedirectionsina
.Passnulltoremovethecontentfromthepanel. setRouteIndex setRouteIndex(routeIndex) Parameters:  routeIndex: number ReturnValue: None Setthe(zero-based)indexoftherouteintheDirectionsResultobjecttorender.Bydefault,thefirstrouteinthearraywillberendered. Inherited: addListener, bindTo, get, notify, set, setValues, unbind, unbindAll Events directions_changed function() Arguments: None Thiseventisfiredwhentherendereddirectionschange,eitherwhenanewDirectionsResultissetorwhentheuserfinishesdraggingachangetothedirectionspath. DirectionsRendererOptions interface google.maps.DirectionsRendererOptions interface ThisobjectdefinesthepropertiesthatcanbesetonaDirectionsRendererobject. Properties directionsoptional Type: DirectionsResultoptional Thedirectionstodisplayonthemapand/orina
panel,retrievedasaDirectionsResultobjectfromDirectionsService. draggableoptional Type: booleanoptional Iftrue,allowstheusertodragandmodifythepathsofroutesrenderedbythisDirectionsRenderer. hideRouteListoptional Type: booleanoptional Default:false Thispropertyindicateswhethertherenderershouldprovideauser-selectablelistofroutesshowninthedirectionspanel. infoWindowoptional Type: InfoWindowoptional TheInfoWindowinwhichtorendertextinformationwhenamarkerisclicked.Existinginfowindowcontentwillbeoverwrittenanditspositionmoved.Ifnoinfowindowisspecified,theDirectionsRendererwillcreateanduseitsowninfowindow.ThispropertywillbeignoredifsuppressInfoWindowsissettotrue. mapoptional Type: Mapoptional Maponwhichtodisplaythedirections. markerOptionsoptional Type: MarkerOptionsoptional Optionsforthemarkers.AllmarkersrenderedbytheDirectionsRendererwillusetheseoptions. paneloptional Type: HTMLElementoptional The
inwhichtodisplaythedirectionssteps. polylineOptionsoptional Type: PolylineOptionsoptional Optionsforthepolylines.AllpolylinesrenderedbytheDirectionsRendererwillusetheseoptions. preserveViewportoptional Type: booleanoptional Default:false Ifthisoptionissettotrueorthemap'scenterandzoomwereneverset,theinputmapiscenteredandzoomedtotheboundingboxofthissetofdirections. routeIndexoptional Type: numberoptional TheindexoftheroutewithintheDirectionsResultobject.Thedefaultvalueis0. suppressBicyclingLayeroptional Type: booleanoptional SuppresstherenderingoftheBicyclingLayerwhenbicyclingdirectionsarerequested. suppressInfoWindowsoptional Type: booleanoptional Suppresstherenderingofinfowindows. suppressMarkersoptional Type: booleanoptional Suppresstherenderingofmarkers. suppressPolylinesoptional Type: booleanoptional Suppresstherenderingofpolylines. DirectionsWaypoint interface google.maps.DirectionsWaypoint interface ADirectionsWaypointrepresentsalocationbetweenoriginanddestinationthroughwhichthetripshouldberouted. Properties locationoptional Type: string|LatLng|Placeoptional Waypointlocation.Canbeanaddressstring,aLatLng,oraPlace.Optional. stopoveroptional Type: booleanoptional Default:true Iftrue,indicatesthatthiswaypointisastopbetweentheoriginanddestination.Thishastheeffectofsplittingtherouteintotwolegs.Iffalse,indicatesthattherouteshouldbebiasedtogothroughthiswaypoint,butnotsplitintotwolegs.Thisisusefulifyouwanttocreatearouteinresponsetotheuserdraggingwaypointsonamap. DirectionsGeocodedWaypoint interface google.maps.DirectionsGeocodedWaypoint interface Asinglegeocodedwaypoint. Properties partial_matchoptional Type: booleanoptional Whetherthegeocoderdidnotreturnanexactmatchfortheoriginalwaypoint,thoughitwasabletomatchpartoftherequestedaddress. place_idoptional Type: stringoptional TheplaceIDassociatedwiththewaypoint.PlaceIDsuniquelyidentifyaplaceintheGooglePlacesdatabaseandonGoogleMaps.LearnmoreaboutPlaceIDsinthePlacesAPIdeveloperguide. typesoptional Type: Arrayoptional Anarrayofstringsdenotingthetypeofthereturnedgeocodedelement.Foralistofpossiblestrings,refertotheAddressComponentTypessectionoftheDeveloper'sGuide. DirectionsRoute interface google.maps.DirectionsRoute interface AsingleroutecontainingasetoflegsinaDirectionsResult.Notethatthoughthisobjectis"JSON-like,"itisnotstrictlyJSON,asitdirectlyandindirectlyincludesLatLngobjects. Properties bounds Type: LatLngBounds Theboundsforthisroute. copyrights Type: string Copyrightstexttobedisplayedforthisroute. legs Type: Array AnarrayofDirectionsLegs,eachofwhichcontainsinformationaboutthestepsofwhichitiscomposed.Therewillbeonelegforeachstopoverwaypointordestinationspecified.SoaroutewithnostopoverwaypointswillcontainoneDirectionsLegandaroutewithonestopoverwaypointwillcontaintwo. overview_path Type: Array AnarrayofLatLngsrepresentingtheentirecourseofthisroute.Thepathissimplifiedinordertomakeitsuitableincontextswhereasmallnumberofverticesisrequired(suchasStaticMapsAPIURLs). overview_polyline Type: string Anencodedpolylinerepresentationoftherouteinoverview_path.Thispolylineisanapproximate(smoothed)pathoftheresultingdirections. summary Type: string Containsashorttextualdescriptionfortheroute,suitablefornaminganddisambiguatingtheroutefromalternatives. warnings Type: Array Warningstobedisplayedwhenshowingthesedirections. waypoint_order Type: Array IfoptimizeWaypointswassettotrue,thisfieldwillcontainthere-orderedpermutationoftheinputwaypoints.Forexample,iftheinputwas:  Origin:LosAngeles  Waypoints:Dallas,Bangor,Phoenix  Destination:NewYorkandtheoptimizedoutputwasorderedasfollows:  Origin:LosAngeles  Waypoints:Phoenix,Dallas,Bangor  Destination:NewYorkthenthisfieldwillbeanArraycontainingthevalues[2,0,1].Notethatthenumberingofwaypointsiszero-based.Ifanyoftheinputwaypointshasstopoversettofalse,thisfieldwillbeempty,sincerouteoptimizationisnotavailableforsuchqueries. fareoptional Type: TransitFareoptional Thetotalfareforthewholetransittrip.Onlyapplicabletotransitrequests. DirectionsLeg interface google.maps.DirectionsLeg interface AsinglelegconsistingofasetofstepsinaDirectionsResult.Somefieldsinthelegmaynotbereturnedforallrequests.Notethatthoughthisresultis"JSON-like,"itisnotstrictlyJSON,asitdirectlyandindirectlyincludesLatLngobjects. Properties end_address Type: string Theaddressofthedestinationofthisleg.Thiscontentismeanttobereadas-is.Donotprogrammaticallyparsetheformattedaddress. end_location Type: LatLng TheDirectionsServicecalculatesdirectionsbetweenlocationsbyusingthenearesttransportationoption(usuallyaroad)atthestartandendlocations.end_locationindicatestheactualgeocodeddestination,whichmaybedifferentthantheend_locationofthelaststepif,forexample,theroadisnotnearthedestinationofthisleg. start_address Type: string Theaddressoftheoriginofthisleg.Thiscontentismeanttobereadas-is.Donotprogrammaticallyparsetheformattedaddress. start_location Type: LatLng TheDirectionsServicecalculatesdirectionsbetweenlocationsbyusingthenearesttransportationoption(usuallyaroad)atthestartandendlocations.start_locationindicatestheactualgeocodedorigin,whichmaybedifferentthanthestart_locationofthefirststepif,forexample,theroadisnotneartheoriginofthisleg. steps Type: Array AnarrayofDirectionsSteps,eachofwhichcontainsinformationabouttheindividualstepsinthisleg. traffic_speed_entry Deprecated:Thisarraywillalwaysbeempty.Type: Array> Informationabouttrafficspeedalongtheleg. via_waypoints Type: Array Anarrayofnon-stopoverwaypointsalongthisleg,whichwerespecifiedintheoriginalrequest.Deprecatedinalternativeroutes.Version3.27willbethelastversionoftheAPIthataddsextravia_waypointsinalternativeroutes.WhenusingtheDirectionsServicetoimplementdraggabledirections,itisrecommendedtodisabledraggingofalternativeroutes.Onlythemainrouteshouldbedraggable.Userscandragthemainrouteuntilitmatchesanalternativeroute. arrival_timeoptional Type: Timeoptional Anestimatedarrivaltimeforthisleg.OnlyapplicableforTRANSITrequests. departure_timeoptional Type: Timeoptional Anestimateddeparturetimeforthisleg.OnlyapplicableforTRANSITrequests. distanceoptional Type: Distanceoptional Thetotaldistancecoveredbythisleg.Thispropertymaybeundefinedasthedistancemaybeunknown. durationoptional Type: Durationoptional Thetotaldurationofthisleg.Thispropertymaybeundefinedasthedurationmaybeunknown. duration_in_trafficoptional Type: Durationoptional Thetotaldurationofthisleg,takingintoaccountthetrafficconditionsindicatedbythetrafficModelproperty.Thispropertymaybeundefinedasthedurationmaybeunknown. DirectionsStep interface google.maps.DirectionsStep interface AsingleDirectionsStepinaDirectionsResult.Somefieldsmaybeundefined.Notethatthoughthisobjectis"JSON-like,"itisnotstrictlyJSON,asitdirectlyincludesLatLngobjects. Properties encoded_lat_lngs Type: string Anencodedpolylinerepresentationofthestep.Thisisanapproximate(smoothed)pathofthestep. end_location Type: LatLng Theendinglocationofthisstep. end_point Deprecated:PleaseuseDirectionsStep.end_location.Type: LatLng Theendinglocationofthisstep. instructions Type: string Instructionsforthisstep. lat_lngs Deprecated:PleaseuseDirectionsStep.path.Type: Array AsequenceofLatLngsdescribingthecourseofthisstep.Thisisanapproximate(smoothed)pathofthestep. maneuver Type: string Containstheactiontotakeforthecurrentstep(turn-left,merge,straight,etc.).Valuesaresubjecttochange,andnewvaluesmaybeintroducedwithoutpriornotice. path Type: Array AsequenceofLatLngsdescribingthecourseofthisstep.Thisisanapproximate(smoothed)pathofthestep. start_location Type: LatLng Thestartinglocationofthisstep. start_point Deprecated:PleaseuseDirectionsStep.start_location.Type: LatLng Thestartinglocationofthisstep. travel_mode Type: TravelMode Themodeoftravelusedinthisstep. distanceoptional Type: Distanceoptional Thedistancecoveredbythisstep.Thispropertymaybeundefinedasthedistancemaybeunknown. durationoptional Type: Durationoptional Thetypicaltimerequiredtoperformthisstepinsecondsandintextform.Thispropertymaybeundefinedasthedurationmaybeunknown. polylineoptional Deprecated:PleaseuseDirectionsStep.encoded_lat_lngs.Type: Arrayoptional Containsanobjectwithasingleproperty,'points',thatholdsanencodedpolylinerepresentationofthestep.Thispolylineisanapproximate(smoothed)pathofthestep. stepsoptional Type: Arrayoptional Sub-stepsofthisstep.Specifiedfornon-transitsectionsoftransitroutes. transitoptional Type: TransitDetailsoptional Transit-specificdetailsaboutthisstep.ThispropertywillbeundefinedunlessthetravelmodeofthisstepisTRANSIT. transit_detailsoptional Type: TransitDetailsoptional DetailspertainingtothisstepifthetravelmodeisTRANSIT. DirectionsPolyline interface google.maps.DirectionsPolyline interface AnobjectcontainingapointspropertytodescribethepolylineofaDirectionsStep. Properties points Type: string Anencodedpolyline. Place interface google.maps.Place interface Containsinformationneededtolocate,identify,ordescribeaplaceforaDirectionsRequestorDistanceMatrixRequest.Inthiscontext,"place"meansabusiness,pointofinterest,orgeographiclocation.Forfetchinginformationaboutaplace,seePlacesService. Properties locationoptional Type: LatLng|LatLngLiteraloptional TheLatLngoftheentitydescribedbythisplace. placeIdoptional Type: stringoptional TheplaceIDoftheplace(suchasabusinessorpointofinterest).TheplaceIDisauniqueidentifierofaplaceintheGoogleMapsdatabase.NotethattheplaceIdisthemostaccuratewayofidentifyingaplace.Ifpossible,youshouldspecifytheplaceIdratherthanaquery.AplaceIDcanberetrievedfromanyrequesttothePlacesAPI,suchasaTextSearch.PlaceIDscanalsoberetrievedfromrequeststotheGeocodingAPI.Formoreinformation,seetheoverviewofplaceIDs. queryoptional Type: stringoptional Asearchquerydescribingtheplace(suchasabusinessorpointofinterest).Anexamplequeryis"Quay,UpperLevel,OverseasPassengerTerminal5HicksonRoad,TheRocksNSW".Ifpossible,youshouldspecifytheplaceIdratherthanaquery.TheAPIdoesnotguaranteetheaccuracyofresolvingthequerystringtoaplace.IfboththeplaceIdandqueryareprovided,anerroroccurs. TravelMode constants google.maps.TravelMode constants ThevalidtravelmodesthatcanbespecifiedinaDirectionsRequestaswellasthetravelmodesreturnedinaDirectionsStep.Specifythesebyvalue,orbyusingtheconstant'sname.Forexample,'BICYCLING'orgoogle.maps.TravelMode.BICYCLING. Constants BICYCLING Specifiesabicyclingdirectionsrequest. DRIVING Specifiesadrivingdirectionsrequest. TRANSIT Specifiesatransitdirectionsrequest. WALKING Specifiesawalkingdirectionsrequest. DrivingOptions interface google.maps.DrivingOptions interface ConfigurestheDirectionsRequestwhenthetravelmodeissettoDRIVING. Properties departureTime Type: Date Thedesireddeparturetimefortheroute,specifiedasaDateobject.TheDateobjectmeasurestimeinmillisecondssince1January1970.ThismustbespecifiedforaDrivingOptionstobevalid.Thedeparturetimemustbesettothecurrenttimeorsometimeinthefuture.Itcannotbeinthepast. trafficModeloptional Type: TrafficModeloptional Thepreferredassumptiontousewhenpredictingdurationintraffic.ThedefaultisBEST_GUESS. TrafficModel constants google.maps.TrafficModel constants Theassumptionstousewhenpredictingdurationintraffic.SpecifiedaspartofaDirectionsRequestorDistanceMatrixRequest.Specifythesebyvalue,orbyusingtheconstant'sname.Forexample,'bestguess'orgoogle.maps.TrafficModel.BEST_GUESS. Constants BEST_GUESS Usehistoricaltrafficdatatobestestimatethetimespentintraffic. OPTIMISTIC Usehistoricaltrafficdatatomakeanoptimisticestimateofwhatthedurationintrafficwillbe. PESSIMISTIC Usehistoricaltrafficdatatomakeapessimisticestimateofwhatthedurationintrafficwillbe. TransitOptions interface google.maps.TransitOptions interface TheTransitOptionsobjecttobeincludedinaDirectionsRequestwhenthetravelmodeissettoTRANSIT. Properties arrivalTimeoptional Type: Dateoptional Thedesiredarrivaltimefortheroute,specifiedasaDateobject.TheDateobjectmeasurestimeinmillisecondssince1January1970.Ifarrivaltimeisspecified,departuretimeisignored. departureTimeoptional Type: Dateoptional Thedesireddeparturetimefortheroute,specifiedasaDateobject.TheDateobjectmeasurestimeinmillisecondssince1January1970.Ifneitherdeparturetimenorarrivaltimeisspecified,thetimeisassumedtobe"now". modesoptional Type: Arrayoptional Oneormorepreferredmodesoftransit,suchasbusortrain.Ifnopreferenceisgiven,theAPIreturnsthedefaultbestroute. routingPreferenceoptional Type: TransitRoutePreferenceoptional Apreferencethatcanbiasthechoiceoftransitroute,suchaslesswalking.Ifnopreferenceisgiven,theAPIreturnsthedefaultbestroute. TransitMode constants google.maps.TransitMode constants Thevalidtransitmodee.g.busthatcanbespecifiedinaTransitOptions.Specifythesebyvalue,orbyusingtheconstant'sname.Forexample,'BUS'orgoogle.maps.TransitMode.BUS. Constants BUS Specifiesbusasapreferredmodeoftransit. RAIL Specifiesrailasapreferredmodeoftransit. SUBWAY Specifiessubwayasapreferredmodeoftransit. TRAIN Specifiestrainasapreferredmodeoftransit. TRAM Specifiestramasapreferredmodeoftransit. TransitRoutePreference constants google.maps.TransitRoutePreference constants ThevalidtransitroutetypethatcanbespecifiedinaTransitOptions.Specifythesebyvalue,orbyusingtheconstant'sname.Forexample,'LESS_WALKING'orgoogle.maps.TransitRoutePreference.LESS_WALKING. Constants FEWER_TRANSFERS Specifiesthatthecalculatedrouteshouldpreferalimitednumberoftransfers. LESS_WALKING Specifiesthatthecalculatedrouteshouldpreferlimitedamountsofwalking. TransitFare interface google.maps.TransitFare interface AfareofaDirectionsRouteconsistingofvalueandcurrency. Properties currency Type: string AnISO4217currencycodeindicatingthecurrencyinwhichthefareisexpressed. value Type: number Thenumericalvalueofthefare,expressedinthegivencurrency. TransitDetails interface google.maps.TransitDetails interface Detailsaboutthedeparture,arrival,andmodeoftransitusedinthisstep. Properties arrival_stop Type: TransitStop Thearrivalstopofthistransitstep. arrival_time Type: Time Thearrivaltimeofthisstep,specifiedasaTimeobject. departure_stop Type: TransitStop Thedeparturestopofthistransitstep. departure_time Type: Time Thedeparturetimeofthisstep,specifiedasaTimeobject. headsign Type: string Thedirectioninwhichtotravelonthisline,asitismarkedonthevehicleoratthedeparturestop. headway Type: number Theexpectednumberofsecondsbetweenequivalentvehiclesatthisstop. line Type: TransitLine Detailsaboutthetransitlineusedinthisstep. num_stops Type: number Thenumberofstopsonthisstep.Includesthearrivalstop,butnotthedeparturestop. trip_short_name Type: string Thetextthatappearsinschedulesandsignboardstoidentifyatransittriptopassengers,forexample,toidentifytrainnumbersforcommuterrailtrips.Thetextuniquelyidentifiesatripwithinaserviceday. TransitStop interface google.maps.TransitStop interface Detailsaboutatransitstoporstation. Properties location Type: LatLng Thelocationofthisstop. name Type: string Thenameofthistransitstop. TransitLine interface google.maps.TransitLine interface Informationaboutthetransitlinethatoperatesthistransitstep. Properties agencies Type: Array Thetransitagencythatoperatesthistransitline. color Type: string Thecolorcommonlyusedinsignageforthistransitline,representedasahexstring. icon Type: string TheURLforaniconassociatedwiththisline. name Type: string Thefullnameofthistransitline,e.g."8AvenueLocal". short_name Type: string Theshortnameofthistransitline,e.g."E". text_color Type: string Thetextcolorcommonlyusedinsignageforthistransitline,representedasahexstring. url Type: string Theagency'sURLwhichisspecifictothistransitline. vehicle Type: TransitVehicle Thetypeofvehicleused,e.g.trainorbus. TransitAgency interface google.maps.TransitAgency interface Informationaboutanagencythatoperatesatransitline. Properties name Type: string Thenameofthistransitagency. phone Type: string Thetransitagency'sphonenumber. url Type: string Thetransitagency'sURL. TransitVehicle interface google.maps.TransitVehicle interface Informationaboutthevehiclethatoperatesonatransitline. Properties icon Type: string AURLforaniconthatcorrespondstothetypeofvehicleusedonthisline. local_icon Type: string AURLforaniconthatcorrespondstothetypeofvehicleusedinthisregioninsteadofthemoregeneralicon. name Type: string AnameforthistypeofTransitVehicle,e.g."Train"or"Bus". type Type: VehicleType Thetypeofvehicleused,e.g.train,bus,orferry. VehicleType constants google.maps.VehicleType constants Possiblevaluesforvehicletypes. Constants BUS Bus. CABLE_CAR Avehiclethatoperatesonacable,usuallyontheground.AerialcablecarsmaybeofthetypeGONDOLA_LIFT. COMMUTER_TRAIN Commuterrail. FERRY Ferry. FUNICULAR Avehiclethatispulledupasteepinclinebyacable. GONDOLA_LIFT Anaerialcablecar. HEAVY_RAIL Heavyrail. HIGH_SPEED_TRAIN Highspeedtrain. INTERCITY_BUS Intercitybus. METRO_RAIL Lightrail. MONORAIL Monorail. OTHER Othervehicles. RAIL Rail. SHARE_TAXI Sharetaxiisasortofbustransportwithabilitytodropoffandpickuppassengersanywhereonitsroute.Generallysharetaxiusesminibusvehicles. SUBWAY Undergroundlightrail. TRAM Abovegroundlightrail. TROLLEYBUS Trolleybus. UnitSystem constants google.maps.UnitSystem constants ThevalidunitsystemsthatcanbespecifiedinaDirectionsRequest. Constants IMPERIAL SpecifiesthatdistancesintheDirectionsResultshouldbeexpressedinimperialunits. METRIC SpecifiesthatdistancesintheDirectionsResultshouldbeexpressedinmetricunits. Distance interface google.maps.Distance interface Arepresentationofdistanceasanumericvalueandadisplaystring. Properties text Type: string Astringrepresentationofthedistancevalue,usingtheUnitSystemspecifiedintherequest. value Type: number Thedistanceinmeters. Duration interface google.maps.Duration interface Arepresentationofdurationasanumericvalueandadisplaystring. Properties text Type: string Astringrepresentationofthedurationvalue. value Type: number Thedurationinseconds. Time interface google.maps.Time interface ArepresentationoftimeasaDateobject,alocalizedstring,andatimezone. Properties text Type: string Astringrepresentingthetime'svalue.Thetimeisdisplayedinthetimezoneofthetransitstop. time_zone Type: string Thetimezoneinwhichthisstoplies.ThevalueisthenameofthetimezoneasdefinedintheIANATimeZoneDatabase,e.g."America/New_York". value Type: Date Thetimeofthisdepartureorarrival,specifiedasaJavaScriptDateobject. DirectionsTravelMode constants google.maps.DirectionsTravelMode constants Deprecated:Deprecatedasof2011.UseTravelModeinstead. DirectionsUnitSystem constants google.maps.DirectionsUnitSystem constants Deprecated:Deprecatedasof2011.UseUnitSysteminstead. Sendfeedback Exceptasotherwisenoted,thecontentofthispageislicensedundertheCreativeCommonsAttribution4.0License,andcodesamplesarelicensedundertheApache2.0License.Fordetails,seetheGoogleDevelopersSitePolicies.JavaisaregisteredtrademarkofOracleand/oritsaffiliates. Lastupdated2022-09-21UTC. [{ "type":"thumb-down", "id":"missingTheInformationINeed", "label":"MissingtheinformationIneed" },{ "type":"thumb-down", "id":"tooComplicatedTooManySteps", "label":"Toocomplicated/toomanysteps" },{ "type":"thumb-down", "id":"outOfDate", "label":"Outofdate" },{ "type":"thumb-down", "id":"samplesCodeIssue", "label":"Samples/codeissue" },{ "type":"thumb-down", "id":"otherDown", "label":"Other" }] [{ "type":"thumb-up", "id":"easyToUnderstand", "label":"Easytounderstand" },{ "type":"thumb-up", "id":"solvedMyProblem", "label":"Solvedmyproblem" },{ "type":"thumb-up", "id":"otherUp", "label":"Other" }] Needtotellusmore? StackOverflow Askaquestionunderthegoogle-mapstag. GitHub Forkoursamplesandtrythemyourself. Discord ChatwithfellowdevelopersaboutGoogleMapsPlatform. IssueTracker Somethingwrong?Sendusabugreport! LearnMore FAQ APIPicker Tutorials Platforms Android iOS Web WebServices ProductInfo PricingandPlans ContactSales Support TermsofService Android Chrome Firebase GoogleCloudPlatform Allproducts Terms Privacy SignupfortheGoogleDevelopersnewsletter Subscribe English BahasaIndonesia Deutsch Español Español–AméricaLatina Français Italiano Polski Português–Brasil TiếngViệt Türkçe Русский עברית العربيّة فارسی हिंदी বাংলা ภาษาไทย 中文–简体 中文–繁體 日本語 한국어



請為這篇文章評分?