1

As background...I'm developing a native Android App using Android Google Map v2. My requirements are as follows:

Requirement #1: Display a satellite image of a specific geographic area bound by two LatLng's. Note these LatLngs represent what I call the "center-line-endpoints" of the rectangular map area I would like to displayed (as opposed to the the Northeast and Southeast corners of the map area). For clarity the map area I want to display is a single hole on a golf course and the two LatLngs I have represent the Tee location and the Pin/hole location for a particular Golf hole.

No problems with this....The solution to this part seems pretty straight forward. I use the following code to display the map with the appropriate bounds:

public void onCameraChange(CameraPosition arg0) {
// Determine the bounds and then move camera
LatLngBounds bounds = new LatLngBounds.Builder()
  .include(TPS_PIN)
  .include(TPS_HOLE)            
  .build();
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 10));    

Requirements #2: Rotate the map image so that in portrait mode the Tee location is at the bottom of the phone's screen and the Pin/hole location is at the top of phone screen.

While there is a method to rotate a map image (CameraPosition.Builder using it's "bearing" parameter) apparently you can't use this in conjunction with the LatLngBounds method (as noted above) to accomplish my goal (bound and rotate the map image). There is another StackOverflow posting (Android maps V2 newLatLngBounds with bearing) where the author has similar objective but unfortunately the answer provided does not solve the problem. However, the responder suggested the following approach if his suggested answer doesn't work (and it doesn't):

"you may need to calculate the target and zoom yourself, using a Projection, so you can set the bounds as part of the first moveCamera() call above."

Unfortunately there are no more details provided. I've looked at Projection but can't see a way to use to accomplish my goal.

Does anyone see a way to accomplish my goal (bound and rotate)? Perhaps there is a way to do this using a Projection? Remember I only have two LatLng points available to me (LatLng of Tee location and Pin/hole location). I'd need to make sure that the entire hole fits on the screen.

As I noted above I need to determine how to rotate the image so that when the phone is in Potrait mode the Tee is at the bottom of the phone screen and the Hole/Pin location is at the top of the screen. Again need to make sure the entire hole (tee & pin/hole) fits in the screen. Is there any way to "pin" a specific LatLng to the bottom of the screen and another LatLng to the top of the phone screen?

Just to reiterate I need a solution that works with Android Maps v2 api.

Any suggestions would be greatly appreciated...even if they are high level "directional" suggestions. That said hopefully "directional" suggestions would have enough detail to allow me connect the dots.

Community
  • 1
  • 1
user2101068
  • 617
  • 1
  • 8
  • 23

1 Answers1

0

Answering my own question here. I'm not sure if this is the best way to accomplish my goals (i.e., display bound rotated image (to 90 degrees) with the appropriate zoom level)..if there are better ways to do this I'd love to hear them.

At a high level here is what I did:

  1. Used LatLngBounds to first get an map image containing my two LatLng coordinates.
  2. Got a projection of that map image to extract/calc other attributes (target, zoom level, slope/bearing) that were then used to display the image.
  3. I then used CameraPosition.Builder() with the aforementioned parameters extracted/calc'd to build and display the final map image.

So this works but I'm not sure this is the most efficient way of achieving my goals. For example, I use the "LatLngBounds" and then "moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 25)" to generate the map so I can extract the zoomLevel. Unfortunately using "moveCamera" method results in an "interim" map image being generated and interimly displayed (at least in the emulator) before the final rotated map image is generated and displayed. Beside the visual "glitch" of having residuals of the first image briefly appearing on the screen it seems like generating an interim map to get key attributes needed for the final map is an inefficient approach.

Perhaps there is a way to get the zoomLevel without actually generating the image? BTW, in my application it's critical that the zoomLevel be set to the maximum level possible while still showing the entire hole. Because the length of any golf hole can vary significantly the zoomLevel can vary significantly between various holes so hence there is no chance that I can just set the zoomLevel to "X" and expect that to work for every hole. Also my solution will need to work with any of the 40K+ golf courses in the world so it's not like I can store the appropriate zoomlevel for each golf hole.

user2101068
  • 617
  • 1
  • 8
  • 23