Complete Procedure for Geographic Centroid Calculation in MIT App Inventor 1. Set Up Your Project • Create a new project in MIT App Inventor, then set up the User Interface with: o Text Inputs for the user to enter latitude and longitude values (two inputs per point). o A Button labeled "Calculate Centroid" to trigger the centroid calculation. o Two Labels to display the results: one for "Centroid Latitude" and the other for "Centroid Longitude". 2. Initialize Global Variables In the Blocks section: • Initialize the following global variables: o global xSum: 0 o global ySum: 0 o global zSum: 0 o global n: 0 (to count the number of points) o global centroidLatitude: 0 o global centroidLongitude: 0 3. Create a Procedure for Fractional Calculation (frac) 1. Create a New Procedure: o Drag out a Procedure block, name it frac, and add an input named value. 2. Inside the Procedure: o Initialize a local variable integerPart:  Use the int block: integerPart = int(value) o Calculate the fractional part:  Set fracValue to value - integerPart. o Use a return block to return fracValue. 4. Main Calculation Logic When the "Calculate Centroid" Button is Clicked: 1. Reset Variables: o Set global xSum to 0. o Set global ySum to 0. o Set global zSum to 0. o Set global n to 0. 2. Loop Through Each Latitude/Longitude Point: o Use a for each item in list block, where the list consists of latitude and longitude pairs. o For each pair:  Convert Latitude and Longitude to Radians: plaintext Copy latRadians = latitude * (π / 180) lonRadians = longitude * (π / 180)  Calculate Cartesian Coordinates: plaintext Copy x = cos(latRadians) * cos(lonRadians) y = cos(latRadians) * sin(lonRadians) z = sin(latRadians)  Accumulate Sums: plaintext Copy global xSum = global xSum + x global ySum = global ySum + y global zSum = global zSum + z global n = global n + 1 5. Calculate Averages After processing all points, calculate the averages and hypotenuse: 1. Calculate Averages: plaintext Copy xAvg = global xSum / global n yAvg = global ySum / global n zAvg = global zSum / global n 2. Calculate the Hypotenuse: plaintext Copy hyp = sqrt(xAvg * xAvg + yAvg * yAvg) 6. Calculate Longitude and Latitude Using conditional blocks to calculate the centroid coordinates: 1. Calculate Longitude: plaintext Copy if xAvg > 0: global centroidLongitude = atan(yAvg / xAvg) else if xAvg < 0: global centroidLongitude = atan(yAvg / xAvg) + 180 else if xAvg == 0: if yAvg < 0: global centroidLongitude = 270 else global centroidLongitude = 90 2. Calculate Latitude: plaintext Copy global centroidLatitude = atan(zAvg / hyp) 7. Convert Radians to Degrees Convert the results back to degrees: plaintext Copy global centroidLatitude = global centroidLatitude * (180 / π) global centroidLongitude = global centroidLongitude * (180 / π) 8. Display Results Finally, use the set Label.Text blocks to display the centroid latitude and longitude: plaintext Copy LabelForLatitude.Text = "Centroid Latitude: " + global centroidLatitude LabelForLongitude.Text = "Centroid Longitude: " + global centroidLongitude