{"id":5512,"date":"2024-12-31T17:21:25","date_gmt":"2024-12-31T17:21:25","guid":{"rendered":"https:\/\/obsidiansofteducation.com\/?page_id=5512"},"modified":"2026-02-03T18:34:14","modified_gmt":"2026-02-03T18:34:14","slug":"compass-app-in-mit-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/compass-app-in-mit-app-inventor\/","title":{"rendered":"Compass App in MIT App Inventor"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">Hello friends and welcome to Obsidian Soft.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">In today\u2019s class, I will teach you how to turn your Android device or iPhone into a compass.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">So, let\u2019s begin.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Create a new project and call it CompassApp. For screen 1 properties, make align horizontal center and align vertical center. Also, this is super important that you make the screen orientation portrait.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Now, we need a nice, vibrant compass image for our app. You can use whatever compass image you like from the internet but use an image with a transparent background and a square size i.e. the length and the width are equal.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I used this image from freepik.com.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Image by rawpixel.com on Freepik&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/18133.jpg\" alt=\"\"\/><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I removed the background by using the free site remove.bg: a really helpful site that I frequently use.&nbsp; I also reduced its size to 500 by 500 pixels as it is a good app development practice not to use huge images. You can reduce image sizes by using Paint on Windows or Preview on MacOS.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">There are also free online websites available that can help you in resizing an image.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Upload the resized compass image with the transparent background in your compass app project. Now, drag and drop a&nbsp;<strong>Canvas<\/strong>&nbsp;from&nbsp;<strong>Drawing and Animation<\/strong>&nbsp;onto the viewer.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Give it a background color of your choice. I am going to give it a black color. Make height and width fill parent.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop an&nbsp;<strong>Image Sprite<\/strong>&nbsp;from&nbsp;<strong>Drawing and Animation<\/strong>&nbsp;onto the canvas.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Choose the uploaded compass image as the picture. In its properties, make originX = 0.5 and originY = 0.5. Drag and drop a\u00a0<strong>Notifier<\/strong>\u00a0from the\u00a0<strong>User Interface<\/strong>. Also, drag and drop an\u00a0<strong>Orientation Sensor<\/strong>\u00a0from\u00a0<strong>Sensors<\/strong>.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>The screen design is done. Let\u2019s go to the blocks section.<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">When the screen is initialized, we have to align our compass image properly on the screen so drag and drop screen1\u2019s initialize event. Inside, first set the size of the image to have the same height and width as the canvas. This will make sure that the image displays completely and utilizes all the space available. Also, make the x and y positions such that the image comes in the center of the screen. This can be achieved by dividing the width of the canvas by 2 to get the x position but we have to consider the width of the image in this calculation too so this is the resulting formula:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">X position = canvas.width \/2 \u2013 imageSprite.width\/2<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Do the same thing for y and change the width to height.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Y position = canvas.height \/2 \u2013 imageSprite.height\/2<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Next, check if the device has an orientation sensor and use the notifier to show alert if it isn\u2019t available.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/33X-uhALLfbv6ucf44FcXe15vO6wTLzZN-i4E8zf5hApDA8ZBMPcwb-ww2yNTo3-ixk6WG3uCUEuZMR7OBIwM9RXNS9nUoN3tzdKming5PRY0wArpWDbLPHDL39agotCg0tPpIQj2dgNTpRJZozIkUA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">The orientation sensor determines how much the device is tilted but it also has an azimuth property. Azimuth is 0 degrees when the top of the device is pointing north, 90 degrees when it is pointing east, 180 degrees when it is pointing south, 270 degrees when it is pointing west, etc. Hence, we use this to make our compass operate so if it is not available, the compass will not work.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">The actual compass code is very simple now.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Whenever the orientation of the device changes, change the compass image heading to azimuth.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/ZAzJVEb-20Mw2WknuUKvhdfzo0KEJxLm4vXX0kmCsnQQZHMoO7yW_2ph5TfUi0KXgdTaaaC1hT0KkB9XgM77et6w8Xya3zlKNxIY1qnQWoK8OZsAlR_vrOJsQdAUtOgg1t2nMLleKveIOUEV5lGxxaQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">We are done and you can see that such simple code has resulted in such a cool app. I hope you will have fun making this app and impressing your friends and family. Thank you for reading \ud83d\ude42.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can also download the project file (aia) from here:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">If you like my tutorials, consider supporting me:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><a href=\"https:\/\/obsidiansoft.gumroad.com\/l\/cxdft\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"372\" height=\"196\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png\" alt=\"\" class=\"wp-image-5381\" style=\"width:198px;height:auto\" srcset=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1.png 372w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/donate-button-1-300x158.png 300w\" sizes=\"auto, (max-width: 372px) 100vw, 372px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>You can have a look at the video here:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<p class=\"responsive-video-wrap clr\"><iframe loading=\"lazy\" title=\"Compass MIT App Inventor | How to make Compass in MIT App Inventor | Orientation Sensor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/_5bXiZXjLqI?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Please like my videos and share it with your friends and family. Also, subscribe to my channel and press the bell icon so you don\u2019t miss any of the great projects I have planned for you.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><a href=\"https:\/\/www.youtube.com\/c\/obsidiansofteducation\" target=\"_blank\" rel=\"noopener\">https:\/\/www.youtube.com\/c\/obsidiansofteducation<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Please like my Facebook page and Instagram page for more educational resources and tips.<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Facebook:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.facebook.com\/ObsidianSoft\/<\/a><\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Instagram:<a href=\"https:\/\/www.blogger.com\/blog\/page\/edit\/4947000819484484884\/7140650632339107612#\" target=\"_blank\" rel=\"noopener\">&nbsp;https:\/\/www.instagram.com\/obsidiansoftapps\/<\/a><\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>Pinterest:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-pinterest wp-block-embed-pinterest\"><div class=\"wp-block-embed__wrapper\">\n<div class=\"oceanwp-oembed-wrap clr\"><iframe loading=\"lazy\" title=\"Obsidian Soft\" src=\"https:\/\/assets.pinterest.com\/ext\/embed.html?grid=obsidiansoft&#038;src=oembed\" height=\"900\" width=\"450\" frameborder=\"0\" scrolling=\"no\" ><\/iframe><\/div>\n<\/div><\/figure>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">For links to free educational apps, have a look at the\u00a0<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/mobile-apps\/\">educational apps page<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello friends and welcome to Obsidian Soft. In today\u2019s class, I will teach you how to turn your Android device or iPhone into a compass. So, let\u2019s begin.&nbsp; Create a new project and call it CompassApp. For screen 1 properties, make align horizontal center and align vertical center. Also, this is super important that you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5512","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/comments?post=5512"}],"version-history":[{"count":2,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5512\/revisions"}],"predecessor-version":[{"id":6873,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5512\/revisions\/6873"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=5512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}