How to add a polygon on google maps? - Stack Overflow

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

Then just provide it to the GoogleMap widget. GoogleMap( polygons: myPolygon(), mapType: MapType.normal, initialCameraPosition: _kGooglePlex, ... 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 Howtoaddapolygonongooglemaps? AskQuestion Asked 2years,11monthsago Modified 2years,7monthsago Viewed 4ktimes 4 1 I'musinggoogle_maps_flutterplugintousegooglemaps.Iwanttodrawapolygonongooglemapswithcoordinatestakenfromtheuser.Thecoordinatestakenaretypeof'Position'object. Ihavealreadytriedusingmap_viewplugintodrawpolygons.Butitdidn'tworkforme. Thisisthecodesnippetwherethecoordinatesarebeingtaken. Geolocatorgeolocator=Geolocator(); StreamSubscription_positionStreamSubscription; finalList_positions=[]; void_toggleListening(){ if(_positionStreamSubscription==null){ constLocationOptionslocationOptions= LocationOptions(accuracy:LocationAccuracy.best,distanceFilter:10); finalStreampositionStream= Geolocator().getPositionStream(locationOptions); _positionStreamSubscription=positionStream.listen( (Positionposition)=>setState(()=>_positions.add(position))); _positionStreamSubscription.pause(); } setState((){ if(_positionStreamSubscription.isPaused){ _positionStreamSubscription.resume(); }else{ _positionStreamSubscription.pause(); } }); androidgoogle-mapsflutterdart Share Follow editedJul2,2019at9:34 sejal.8 askedJul2,2019at9:27 sejal.8sejal.8 6911silverbadge77bronzebadges Addacomment  |  1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 2 Well,ifyoucanconvertthecoordinatesofyourPositionobjectstoLatLngobjects,thenyoucanusegoogle_maps_flutteritselftodrawpolygons.YoucanseethatoneofitsparametersallowsforPolygons.Sojustbuildingupontheexamplefromgoogle_maps_flutter,we'llfirstsetupourpolygon: SetmyPolygon(){ ListpolygonCoords=newList(); polygonCoords.add(LatLng(37.43296265331129,-122.08832357078792)); polygonCoords.add(LatLng(37.43006265331129,-122.08832357078792)); polygonCoords.add(LatLng(37.43006265331129,-122.08332357078792)); polygonCoords.add(LatLng(37.43296265331129,-122.08832357078792)); SetpolygonSet=newSet(); polygonSet.add(Polygon( polygonId:PolygonId('test'), points:polygonCoords, strokeColor:Colors.red)); returnpolygonSet; } ThenjustprovideittotheGoogleMapwidget. GoogleMap( polygons:myPolygon(), mapType:MapType.normal, initialCameraPosition:_kGooglePlex, onMapCreated:(GoogleMapControllercontroller){ _controller.complete(controller); }, ), ThiswilldrawasmalltriangleneartheGooglePlex. Formoreinformationonthisfeature,youcanrefertotheAndroiddocumentationofMapsSDKShapes.TheAPIusageshouldbesame,ifnotsimilar,soyoucanuseitasaguideline. Share Follow editedNov12,2019at19:30 answeredNov12,2019at19:21 TWLTWL 5,4872424silverbadges6262bronzebadges 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?Browseotherquestionstaggedandroidgoogle-mapsflutterdartoraskyourownquestion. TheOverflowBlog ExpertsfromStripeandWaymoexplainhowtocraftgreatdocumentation(Ep.455) Askedandanswered:theresultsforthe2022Developersurveyarehere! FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Testingnewtrafficmanagementtool AskWizardTestResultsandNextSteps Trending:Anewanswersortingoption Related 2809 HowcanIsaveanactivitystateusingthesaveinstancestate? 2248 HowdoIcentertexthorizontallyandverticallyinaTextView? 4199 Howtoclose/hidetheAndroidsoftkeyboardprogrammatically? 3093 HowtostopEditTextfromgainingfocuswhenanactivitystartsinAndroid? 706 GoogleMapsJSAPIv3-SimpleMultipleMarkerExample 2637 HowcanIfix'android.os.NetworkOnMainThreadException'? 0 GoogleMapsPolygonDrawingShortestDistanceProblem 0 CheckifthepointiswithintheGoogleMapspolygoninflutter HotNetworkQuestions Whatisthemeaningof"payinginbuttons"? RouteMapping:Roadchoice whydoesthedataisendtotheservergetroundedoffandhowdoisendtheentirefloatinstead TryingtoidentifysomethingIsawinthesky Howcouldacreaturemakeitsfeathersorhairsglow? NaturalMedicinewithBattleMedicine StartupDiskCreatordoesnotexist Isitbadpracticetocomparestringrepresentationonanobjectinsteadofitspropertiesduringunittests? Ifaplayercastsaspellofunlimiteddurationandretrainsoutofit,doesthespellremainactive? Petitmatin/Grandmatin Ihavetwopassportsfromthesamecountrywithadifferentnamespelling.Issueswhentraveling? Travelvisaappointment-Whatexactlyispassportphotocopy? Howtogetaresearchpaperpublishedaftertheauthorhasdied? Whatwouldbetheleastphysicsbreakingwaytotravelatlightspeedorfaster? HowdosmalllocalMalayrestaurantsinnon-touristyareasinMalaysiawork? Whatarebestpracticesfortestingtheabsenceoffunctionality InP.J.Plauger's"TheStandardCLibrary"(1992),whyareforloopsusedsofrequentlyinsteadofwhileloopsintheimplementations? Extendingsignalduration WeknowClassicalMechanicsiswrong.ButcanwealsosayeveryothertheoryiswrongexcepttheTheoryofEverything? WhichUSGovernmentAgencywouldhandlethecoverupofanewmineralfoundonadifferentplanet? backwardS_hybriD-snakE_kebaB-cameL_case Auto-Launchappfromthedmg WhathappenedtothelastworkGaunceLewiswasdoingwhenhedied? WouldpubliclyfartingonapictureoftheEnglishmonarchactuallyqualifyastreasonin1798? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-dart Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?