{"id":3532,"date":"2012-05-04T07:46:24","date_gmt":"2012-05-04T12:46:24","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=3532"},"modified":"2012-05-04T07:49:53","modified_gmt":"2012-05-04T12:49:53","slug":"plot-google-map","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2012\/05\/04\/plot-google-map\/","title":{"rendered":"Plot Google Map"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27627-zoharby-plot-google-map\">plot_google_map<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/96707\">Zohar Bar-Yehuda<\/a>.\r\n   <\/p>\r\n   <p>This pick comes from <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/225623\">Chad's<\/a> response to <a href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/04\/13\/what-is-your-favorite-unrecognized-file-exchange-submission\/\">Brett's post<\/a>. He says, \"plot_google_map is not only cool, it&#8217;s also very easy to use and incredibly useful for plotting spatial data.\"\r\n      I played around with this entry and I agree. It's very easy to use; you simply call the function, and it overlays a map on\r\n      the current axes based on the latitude and longitude ranges. The part that I really like is the auto-refresh behavior, which\r\n      automatically refreshes the map when I zoom into the map.\r\n   <\/p>\r\n   <p>Here's the driving route from our headquarter (Natick, MA) to Boston Logan Airport. You should run this and try zooming into\r\n      the map. Download the data <a href=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plot_google_map\/NatickToBOS.mat\">here<\/a>.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\"><span style=\"color: #228B22\">% load route data<\/span>\r\nload <span style=\"color: #A020F0\">NatickToBOS<\/span>\r\n\r\n<span style=\"color: #228B22\">% plot route data<\/span>\r\nplot(Data001(:, 1), Data001(:, 2), <span style=\"color: #A020F0\">'r'<\/span>, <span style=\"color: #A020F0\">'LineWidth'<\/span>, 2);\r\nline(Data001(1, 1), Data001(1, 2), <span style=\"color: #A020F0\">'Marker'<\/span>, <span style=\"color: #A020F0\">'o'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Color'<\/span>, <span style=\"color: #A020F0\">'b'<\/span>, <span style=\"color: #A020F0\">'MarkerFaceColor'<\/span>, <span style=\"color: #A020F0\">'b'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 10);\r\nline(Data001(end, 1), Data001(end, 2), <span style=\"color: #A020F0\">'Marker'<\/span>, <span style=\"color: #A020F0\">'s'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Color'<\/span>, <span style=\"color: #A020F0\">'b'<\/span>, <span style=\"color: #A020F0\">'MarkerFaceColor'<\/span>, <span style=\"color: #A020F0\">'b'<\/span>, <span style=\"color: #A020F0\">'MarkerSize'<\/span>, 10);\r\nxlim([-71.4, -71]); axis <span style=\"color: #A020F0\">equal<\/span> <span style=\"color: #A020F0\">off<\/span>\r\n\r\n<span style=\"color: #228B22\">% Google map<\/span>\r\nplot_google_map(<span style=\"color: #A020F0\">'maptype'<\/span>, <span style=\"color: #A020F0\">'roadmap'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plot_google_map\/potw_plot_google_map_01.png\"> <p>One suggestion I have is to add the auto-refresh behavior for panning, in addition to zooming. It's very simple to do that.\r\n      There's a section in the code that implements this for the zoom action:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">zoomHandle = zoom;\r\nset(zoomHandle, <span style=\"color: #A020F0\">'ActionPostCallback'<\/span>, @update_google_map);<\/pre><p>You can do the same thing for the pan action like this:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">panHandle = pan;\r\nset(panHandle, <span style=\"color: #A020F0\">'ActionPostCallback'<\/span>, @update_google_map);<\/pre><p>With this, if you pan the map, the graphics will update after releasing the mouse.<\/p>\r\n   <p>Thanks Zohar for the entry and Chad for the recommendation!<\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give this a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=3532#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27627-zoharby-plot-google-map#comments\">comment<\/a> for Zohar.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_84a0d9f3331042a6913112114f1c23c5() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='84a0d9f3331042a6913112114f1c23c5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 84a0d9f3331042a6913112114f1c23c5';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2012 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_84a0d9f3331042a6913112114f1c23c5()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.14<br><\/p>\r\n<\/div>\r\n<!--\r\n84a0d9f3331042a6913112114f1c23c5 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27627-zoharby-plot-google-map\r\n% plot_google_map> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/96707 Zohar\r\n% Bar-Yehuda>.\r\n%\r\n% This pick comes from\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/225623\r\n% Chad's> response to\r\n% <https:\/\/blogs.mathworks.com\/pick\/2012\/04\/13\/what-is-your-favorite-unrecognized-file-exchange-submission\/\r\n% Brett's post>. He says, \"plot_google_map is not only cool, it\u00e2\u20ac\u2122s also very\r\n% easy to use and incredibly useful for plotting spatial data.\" I played\r\n% around with this entry and I agree. It's very easy to use; you simply\r\n% call the function, and it overlays a map on the current axes based on the\r\n% latitude and longitude ranges. The part that I really like is the\r\n% auto-refresh behavior, which automatically refreshes the map when I zoom\r\n% into the map.\r\n%\r\n% Here's the driving route from our headquarter (Natick, MA) to Boston\r\n% Logan Airport. You should run this and try zooming into the map. Download\r\n% the data\r\n% <https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_plot_google_map\/NatickToBOS.mat\r\n% here>.\r\n\r\n% load route data\r\nload NatickToBOS\r\n\r\n% plot route data\r\nplot(Data001(:, 1), Data001(:, 2), 'r', 'LineWidth', 2);\r\nline(Data001(1, 1), Data001(1, 2), 'Marker', 'o', ...\r\n    'Color', 'b', 'MarkerFaceColor', 'b', 'MarkerSize', 10);\r\nline(Data001(end, 1), Data001(end, 2), 'Marker', 's', ...\r\n    'Color', 'b', 'MarkerFaceColor', 'b', 'MarkerSize', 10);\r\nxlim([-71.4, -71]); axis equal off\r\n\r\n% Google map\r\nplot_google_map('maptype', 'roadmap');\r\n\r\n%%\r\n% One suggestion I have is to add the auto-refresh behavior for panning, in\r\n% addition to zooming. It's very simple to do that. There's a section in\r\n% the code that implements this for the zoom action:\r\n%\r\n%   zoomHandle = zoom;\r\n%   set(zoomHandle, 'ActionPostCallback', @update_google_map);\r\n%\r\n% You can do the same thing for the pan action like this:\r\n%\r\n%   panHandle = pan;\r\n%   set(panHandle, 'ActionPostCallback', @update_google_map);\r\n%\r\n% With this, if you pan the map, the graphics will update after releasing\r\n% the mouse.\r\n%\r\n% Thanks Zohar for the entry and Chad for the recommendation! \r\n%\r\n% *Comments*\r\n%\r\n% Give this a try and let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=3532#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27627-zoharby-plot-google-map#comments\r\n% comment> for Zohar.\r\n\r\n##### SOURCE END ##### 84a0d9f3331042a6913112114f1c23c5\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is plot_google_map by Zohar Bar-Yehuda.\r\n   \r\n   This pick comes from Chad's response to Brett's post. He says, \"plot_google_map is not only cool, it&#8217;s also very easy... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2012\/05\/04\/plot-google-map\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3532"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=3532"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3532\/revisions"}],"predecessor-version":[{"id":3538,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/3532\/revisions\/3538"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=3532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=3532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=3532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}