Good morning

While running the app two linestrings intersect at some point on the map. Is it possible to determine at that moment the latitude and longitude coordinates at the crossover point? If so, what is the way to obtain the data? thanks

Certainly.

Constantly poll the result using a Clock: when an intersection occurs, the app will let you know. Provide code to provide the time of intersection and you can capture that too. Turn off the Timer once that happens?

DistanceToFeature( *mapFeature* , *centroids* ) computes the distance between the `LineString`

and the given `mapFeature`

. If an error occurs, this method will return -1.

To get the geocoordinates of the Intersection **might** be possible. Use the coordinates of end points of each LineString and use Math to calculate the coordinates of the intersection. Try it and tell us how you did it?

Ok. ill try, but I dont know what type of math should I do. Could you guide me?

- calculate the slope of each line string (you will need the end point coordinates to calculate the intersection of two lines)
- calculate the intersection of two lines (google advice )

You need to solve simultaneous equations. You could use the Math blocks but you will probably need an extension. Math extensions.**might**be useful.

or you might be able to use a html or javascript solution in your App inventor app for linear equations .

Street Lat ini Long ini Lat end Long end

18 -34.9109761 -57.9801846 -34.9413552 -57.9393816

56 -34.9123857 -57.939446 -34.9403076 -57.970202

This 2 lines might cross. What should I rest or sum to find the crossingpoint?

ok I willl try to read all the documents before come back again. Thank you

Here is a javascript solution that calculates the intersection point of the two line strings you described.

Thanks Steve. I found the same using C#

static PointF FindIntersection(PointF s1, PointF e1, PointF s2, PointF e2) {

float a1 = e1.Y - s1.Y;

float b1 = s1.X - e1.X;

float c1 = a1 * s1.X + b1 * s1.Y;

```
float a2 = e2.Y - s2.Y;
float b2 = s2.X - e2.X;
float c2 = a2 * s2.X + b2 * s2.Y;
float delta = a1 * b2 - a2 * b1;
//If lines are parallel, the result will be (NaN, NaN).
return delta == 0 ? new PointF(float.NaN, float.NaN)
: new PointF((b2 * c1 - b1 * c2) / delta, (a1 * c2 - a2 * c1) / delta);
```

I just made the calculations and it works. Now I will try to implement using blocks

This should go into the map component

Using your code Enrique I get this result for the intersection of the two line strings.

Is the latitude/longitude of the calculated intersection reasonable?

@TIMAI2 The Math Blocks provide the intersection; just need a way to automatically capture the start and end coordinates of each LineString to populate the coordinates to the Math Blocks.

Are you busy? Have to put this away to get some lunch and do some outside work.

The coordinates are -34.92818729 -57.95690656. I am now trying to get the values from my list (I have an issue with lists). Anyway it is a matter of adjusting values but the math is apparently working. Thanks

In case if anyone is interested in a general solution. The following example determines the Intersection coordinates of two LineStrings based on a conversation with Enrique and the C# algorithm I ported to App Inventor. The example places a Marker at that intersection point.

LineStringMapIntersectionPoint.aia (8.3 KB) :

Steve. After yesterday's exchanges I was able to implement your suggestions in my app and everything worked as expected. Thank you for your input.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.