[FREE] Calculate areas and distances on maps precisely

Introduction
The CalculateMapArea, written in Java, is an extension designed for the MIT App Inventor platform. It facilitates drawing and calculating areas on a map. This overview is aimed at users familiar with the block-based language of MIT App Inventor but not necessarily with Java.

Constructor

  • CalculateMapArea(ComponentContainer container): Initializes the extension with the given component container.

Properties Setters and Getters

  • SetLineMapDraw(boolean isLineString): Defines whether to draw a LineString on the map.
  • GetLineMapDraw(): Returns a boolean indicating if a LineString is being drawn.
  • SetPolygonMapDraw(boolean isPolygon): Sets the drawing mode to polygon if true.
  • SetPolygonMapDraw(): Retrieves the boolean status indicating if the polygon drawing mode is set.

Drawing and Map Component Methods

  • SetMapComponent(Map map): Associates a Map component with the extension for drawing.
  • AddPoint(double latitude, double longitude): Adds a point to the current drawing (polygon or line string) based on latitude and longitude.
  • DrawLineString(): Renders the LineString on the map using the added points.
  • SetLineStyle(int color, int strokeWidth): Defines the style of the line (color and stroke width).
  • SetPolygonStyle(int fillColor, int strokeColor, int strokeWidth): Sets the style for the polygon (fill color, stroke color, and stroke width).
  • DrawMarker(): Draws markers on the map for each point added.
  • DrawPolygon(): Renders the polygon on the map using the specified points.

Utility and Calculation Methods

  • GetOrderedPointsYailList(): Returns an ordered list of points (YailList) for the drawn shape.
  • CalculateArea(): Calculates and returns the area of the drawn polygon.
  • calculateDistance(double lat1, double lon1, double lat2, double lon2): Computes the distance between two points, considering Earth's curvature.
  • CalculateTotalLineDistance(): Calculates the total distance of the line segments added.
  • ResetArea(YailList featuresToRemove): Resets the area points and removes specified features from the map.

Event

  • ReportError(String errorMessage): Triggers an event to report an error with a custom message.

Explanation in Block Language Context

In the context of MIT App Inventor's block language:

  • Constructors are like initialization blocks that set up the extension.
  • Setters and Getters (SetLineMapDraw, GetLineMapDraw, etc.) are blocks that set or retrieve properties.
  • Drawing methods (AddPoint, DrawLineString, etc.) are action blocks that modify the map.
  • Utility functions (CalculateArea, calculateDistance, etc.) are similar to blocks that perform calculations or specific tasks.
  • Events (ReportError) work like event handlers in App Inventor, triggering when specific conditions are met.

This class essentially allows users to draw shapes on a map and calculate related data, like area and distances, using a familiar block-like approach.


Files

Demo

5 Likes

Rename its to javafile.aia, upload here

2 Likes

Good work :+1: Keep it up :running_woman:

You may make it open source on your GitHub by making a repository. Otherwise you may rename it as .txt file.

2 Likes

I decided to share it on GitHub.

2 Likes

Good work :+1: Keep it up :smiling_face_with_three_hearts: @Passos_0213

2 Likes

Please share the apk link...

Great :+1:. But how can i show the area result in acre instead of m^2

One Acre is equal to 4046.85642199999983859016 Square Meters

So divide m^2 by 4047 to get acres.

I don't know extension is giving results in m^2 or in km^2 or in m ..?

What is this about..?

See the AIA example I developed.

The map can't view properly with satellite mode..bad experience..

For some locations in the world, OSM does not provide the Aerial map tiles necessary to display 'satellite mode' when using the Map component. Lack of satellite map images probably occurs when using high magnification (zoom modes greater than about 13 or so)..

Solution: Use a Google Map or a Microsoft Bing Map instead of the Map component to render your maps which provide coverage of more locations with satellite map tile then can be achieved using the Map component OSM tiles.

1 Like

Can you explain it in block section?

Perhaps reading this topic will explain this for you.

both alternative mapping options have higher resolution aerial map tiles for most of the world at high map zoom than is possible using the Map component (which uses OpenStreetMap tiles)

It is impossible to be able to use high resolution aerial map tiles for some locations using the Map component..