native.newMapView and setRegion

I originally posted this in the Native UI forum, but got no response. My apologies for cross posting, but I’m hoping someone here can answer this one:

According to the docs, and apparently, though not always reliably, I can use “myMap:setRegion” to center the map on a given location with a span of a given degree in latitude and longitude.

What I cannot figure out how to do is to center the map on two locations, the map spanning the distance of those two locations.

Meaning,

My map shows “You are here” (myLocation = myMap:getUserLocation)
I add a marker “We are here” (myMap:addMarker( latitude, longitude, { title=“We are here”, subtitle=“our address” } )

I want to zoom the map to show both locations, so the user has a sense of in which direction we are.

Hopefully, one day, we will get routing; but until then, I’d like to just show my user both places on the map. With the map zoomed to show both locations at the outer visible extremes of the map view. [import]uid: 74957 topic_id: 32932 reply_id: 332932[/import]

You need to do a little basic math…

What you need to end up with, to call the corona functions, is a center point, and a view span…

To get the view span, you’re going to need to do something along the lines of:

  • subtract the 2 points lattitudes from each other. (lat span)
  • subtract the 2 points longitutes from each other (long span)

To get the centerpoint, you’ll need to add the coords together, and divide by two…

Careful with your use of math.abs() during the whole thing! [import]uid: 79933 topic_id: 32932 reply_id: 130826[/import]

You need to do a little basic math…

What you need to end up with, to call the corona functions, is a center point, and a view span…

To get the view span, you’re going to need to do something along the lines of:

  • subtract the 2 points lattitudes from each other. (lat span)
  • subtract the 2 points longitutes from each other (long span)

To get the centerpoint, you’ll need to add the coords together, and divide by two…

Careful with your use of math.abs() during the whole thing! [import]uid: 79933 topic_id: 32932 reply_id: 130826[/import]