plot_google_map.musestheGoogleMapsAPItoplotamapinthebackgroundofthecurrentfigure.ItassumesthecoordinatesofthecurrentfigureareintheWGS84datum,andusesaconversioncodetoconvertandprojecttheimagefromthecoordinatesystemusedbyGoogleintoWGS84coordinates.Thezoomlevelofthemapisautomaticallydeterminedtocovertheentireareaofthefigure.Additionally,ithastheoptiontoauto-refreshthemapuponzoominginthefigure,revealingmoredetailsasonezoomsin.
Thefollowingcodeproducesthescreenshot:
plot_google_map('apiKey','<Your_API_Key>')%Youonlyneedtorunthisonce,whichwillstoretheAPIkeyinamatfileforallfutureusageslat=[48.870851.518841.926040.431252.52337.982];lon=[2.4131-0.130012.4951-3.678813.41523.715];plot(lon,lat,'.r','MarkerSize',20)plot_google_mapPrerequisitesDuetochangestotheGoogleMapsbillingmodel,younowmustsetyourownGoogleMapsAPIkeyandenablebillingforyourproject(seeinstructionshere).You'regettinganautomaticcreditof200$/month,whichwillbeenoughfor100,000staticmapscallswithoutactuallybeingbilled-moredetailshere.
Notethatthisdoesposesomechallengesifyouwanttodeployyourcode,asyourAPIkeywillneedtobedeployedwiththecode/asamatfileandhencemaybeexposedtousers.
KnownIssuesSavingthemapwithanimage/matrixoverlaydrawnontopofit(especiallyasemi-transparentone)cansometimescauseunexpectedresults(mapnotshowingetc.).Ifyou'reencounteringsuchproblems,it'srecommendedtousetheexport_figsubmission:https://www.mathworks.com/matlabcentral/fileexchange/23629-exportfigThecombinationthatseemstoworkbest:set(gcf,'renderer','zbuffer')export_fig('out.jpg')
评论