{"id":5509,"date":"2024-12-31T17:18:42","date_gmt":"2024-12-31T17:18:42","guid":{"rendered":"https:\/\/obsidiansofteducation.com\/?page_id=5509"},"modified":"2026-03-03T15:40:50","modified_gmt":"2026-03-03T15:40:50","slug":"qibla-finder-or-location-finder-app-in-mit-app-inventor","status":"publish","type":"page","link":"https:\/\/obsidiansofteducation.com\/index.php\/qibla-finder-or-location-finder-app-in-mit-app-inventor\/","title":{"rendered":"Qibla Finder or Location Finder 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 into a Qibla app. A qibla app is an app that points toward Kaaba (the holiest place for muslims around the world). They have to pray five times a day while facing Kaaba so having a qibla app is a must in their lives. However, you can turn this app into your&nbsp;<strong>home finder<\/strong>&nbsp;or some other&nbsp;<strong>location direction app<\/strong>&nbsp;too by providing a different longitude and latitude.&nbsp;We will use the longitude and latitude of&nbsp;<strong>Kaaba<\/strong>&nbsp;located in Makkah, Saudi Arabia.<\/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\/snake20game2016.png\" alt=\"\"\/><\/figure>\n<\/div>\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 QiblaApp. For screen 1 properties, make align horizontal center and align vertical center. Make the screen orientation portrait.&nbsp;<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">I will upload a compass image and an arrow image. Use a square compass image with a transparent background.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">You can download the compass image from here:<br>https:\/\/www.freepik.com\/free-vector\/illustration-compass_2807758.htm<br><br>You can remove the background of the image by using:<br>https:\/\/www.remove.bg\/<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop a&nbsp;<strong>Label<\/strong>&nbsp;from the&nbsp;<strong>User Interface<\/strong>&nbsp;and rename it to addressLbl. Now, drag and drop a&nbsp;<strong>Canvas<\/strong>&nbsp;from&nbsp;<strong>Drawing and Animation<\/strong>&nbsp;onto the viewer. Make height and width 500 pixels.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop an\u00a0<strong>Image Sprite<\/strong>\u00a0from\u00a0<strong>Drawing and Animation<\/strong>\u00a0onto the canvas. Rename to compassImg and choose the uploaded compass image as the picture. Make height and width fill parent. Scroll down in the properties and make originX = 0.5 and originY = 0.5.\u00a0<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop another\u00a0<strong>Image Sprite<\/strong>\u00a0from\u00a0<strong>Drawing and Animation<\/strong>\u00a0onto the canvas. Rename to arrowImg and choose the uploaded arrow image as the picture.\u00a0 Make height 150 pixels and width 84 pixels. Also, make originX = 0.5 and originY = 0.5.\u00a0<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop an&nbsp;<strong>Orientation Sensor<\/strong>&nbsp;from&nbsp;<strong>Sensors<\/strong>.<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\">Drag and drop a location sensor from sensors and choose 1000 as timeinterval.<\/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\">First of all, make global variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img loading=\"lazy\" decoding=\"async\" height=\"399\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/krezMJMEufNcqTD3i_h-YwOHM8Uh3YAdcxvPwJ61C53jrOxaF1WQgGj5tX8P2Gh82qCrV3RnTrKH2Zp-Vs5k7Vrol9ourSOITPBr9Zp45eJgOkqXTno44TTbeTviLBkHzTjDAxr7mkM5YptxasTiEc.png\" width=\"602\">We are giving invalid values to user longitude and latitude so that we are able to distinguish when actual values are available. The longitude can\u2019t be more than 180&nbsp; and the latitude cannot be more than 90. When the screen is initialized, we need to ask for location permission so get askForPermission block from screen1 and choose course location.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/zKkyfkulENpjrZV1DYmvyG9uAJXJMyhoTwvTbXfwU6UvrX9-2ODbbVSSv0KZtY5zofUUwYpFYx0gjCeVr7kD-Jpca5pv2TmNtYFhZCWFdnWkQYnGXrDpIDHgLdJZ6qtGCcJhWH_Rgom6CDS8si-uEi0.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also, we have to align our compass image and arrow image in center of canvas.&nbsp;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=\"wp-block-paragraph\">X position = canvas.width \/2 \u2013 compassImg.width\/2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do the same thing for y and change the width to height.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Y position = canvas.height \/2 \u2013 compassImg.height\/2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do the same thing for the arrowImg.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"465\" src=\"http:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2026\/03\/blocks-2026-03-03T202658.616-1024x465.png\" alt=\"\" class=\"wp-image-6879\" srcset=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2026\/03\/blocks-2026-03-03T202658.616-1024x465.png 1024w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2026\/03\/blocks-2026-03-03T202658.616-300x136.png 300w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2026\/03\/blocks-2026-03-03T202658.616-768x349.png 768w, https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2026\/03\/blocks-2026-03-03T202658.616.png 1084w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"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\/3xRRBgB328l37RFZ1iwCyo2EEH86zAHxy96ZtSM5da1DG9OVGztpicXR1ORpHT3Pa5F_mQMjYFGdjAgPAXsv0ZcNnVvLhhqq17n1iJXEKSHzrka_SAy3VHzZZtKa0sy3Pzys-wG1g7s3p5WKTubvAD0.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, we come to our qibla or location arrow. We need the user\u2019s current location for it so we should only calculate direction if user\u2019s location is available.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/IWK1CBIXoeuipAk-04tMKvINzHDt2_8h6HIcFLbLtbOf9TDD8e7l-qyYjq4_-6QQ4gPXiPaRr3DPfQAMswHRmvy9O_uBz9pKY_Y3a2-8saHO68XmDww0kjP4Xiv6KFFGhqJryCmpc1TJdkKRn1MpOIg.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So call procedure only if valid longitude and latitude.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s work on the procedure now. Please copy the code carefully.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/Z1V8nLmP5FABjuw8349kLzNBOH8N8w1Xs8oiqAnNSupKFnF20s2hCEauXCzEcYxeo1-R_amN5CE7Cln_2j685lHv__j9VlMWF-w6tdRMhJbNhC9OO__RJerp16JjSe2gOqsl2OXsxNiYLL0aC_ILSnc.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">It uses a trigonometric formula to calculate the direction:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Qibla direction = atan2(y,x)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Where y = sin (qiblaLongitude \u2013 userLongitude)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And x= (Cos (userLatitude)x tan(qiblaLatitude))-(sin(userLatitude) x cos (qiblaLongitude \u2013 userLongitude)).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Source: The Qibla equation was derived by&nbsp;<a href=\"http:\/\/www.geomete.com\/abdali\" target=\"_blank\" rel=\"noopener\">Dr. Kamal Abdali<\/a>.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And then, subtract the calculated angle from true north i.e. azimuth to get the custom location direction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Last but not least, we come to the location sensor code. When the device receives location information, the location changed event is triggered.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/obsidiansofteducation.com\/wp-content\/uploads\/2024\/12\/ShcxjBdHaIuK7GH6z40bl7oa1c5JwD60uD4nVqamGDN7B7xKEBpHp53YrlXqhaoVqdDkYxIPQWr-IIv5tmlsMUaL3_b_qERwy03dQmULEBUsLatLoTVofXkWy7mjauvt8m5obpQZxI6wzmb6IjXwr5s.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We are done and you can see that although the trigonometric code was a bit complicated but if you follow it carefully, it will result in a very, very cool app that you can show to friends and family and impress them. Thank you for reading \ud83d\ude42.<\/p>\n\n\n\n<p class=\"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:244px;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=\"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=\"App Inventor Qibla Finder | Location Finder | Qibla Finder App Inventor | Qibla Compass App Inventor\" width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/eVXTmzrBNuQ?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=\"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=\"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=\"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=\"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=\"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=\"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=\"wp-block-paragraph\"><strong>For links to free educational apps, have a look at the&nbsp;<a href=\"https:\/\/obsidiansofteducation.com\/index.php\/mobile-apps\/\">educational apps page<\/a><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/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 into a Qibla app. A qibla app is an app that points toward Kaaba (the holiest place for muslims around the world). They have to pray five times a day while facing Kaaba so having [&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-5509","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5509","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=5509"}],"version-history":[{"count":2,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5509\/revisions"}],"predecessor-version":[{"id":6880,"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/pages\/5509\/revisions\/6880"}],"wp:attachment":[{"href":"https:\/\/obsidiansofteducation.com\/index.php\/wp-json\/wp\/v2\/media?parent=5509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}