1

I am trying to create a prototype that could guide a person to his destination place.

  • place is a wide building with several floors.
  • i can obtain/retrieve the maps (still images). e.g. current:1F destination:5F; so I can get the still images of 1st,2nd...5th floors (5 image files).

Scenario:

  1. start the application
  2. input the current location (or may automatically set using current location) & destination
  3. click the search route button to search the maps to use (still images) & mark the current location & destination
  4. update the current location upon moving/going to destination

Problem:

  1. I just need to display 1 image file (each floor) at a time then move to other floor by using scroll bar. But.. don't know how to display it.
  2. I can get the current location coordinate via WiFi but don't know how to put it into still image to mark the current location.

For sure there is already look a like sample application available. Could you share the concepts/ideas or would you include the code snippets. Big Help with my thesis.

Any guidance on the right direction is appreciated.

eros
  • 4,946
  • 18
  • 53
  • 78
  • I've seen a lot of samples but it uses dynamic map (google map). Anybody encountered using still images as map? – eros Aug 15 '11 at 09:11
  • You have several questions rolled up in to one. Divide and conquer. – Dan S Aug 15 '11 at 09:39
  • Oh yes, I realize that need to segregate. I will create a new question and let me to refer back. – eros Aug 16 '11 at 00:06

1 Answers1

1

You have a couple possibilities, create your own MapView like object to provide scrolling ot overlay your map on the Google Api. Example usage of the MapView Api is available through the Location dev guide.

To do this via your own View will be easier if you understand basic graphics programming and transformations for zoom and pan. (If you're good at math it will be no trouble to learn). Use an ImageView with android:scaleType="matrix" override the MotionEvent handler to get the touches then process them into a tranlation and zoom matrix.

To associate the indicator to the image make two pixels into anchor points that coorespond to a real life lat/long. Usually its (0,0) and (width,height) of a rectangular image. Make your life easier and make sure the images are to scale. Then using a second ImageView (for the indicator) draw it on top and move it to the correct place on the screen and make sure the background in this View is transparent as well as the background of your indicator or you'll have a rectangular block "halo".

Be sure to check the accuracies of each location given by the LocationManager.

Additional Content

onCurrentPosition(Location current){
    double hypotenuse = upperLeft.distanceTo(current);
    double bearing = upperLeft.bearingTo(current);
    double currentDistanceX = Math.cos(bearing) * hypotenuse;
    //                     "percentage to mark the position"
    double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;

    moveIndicatorX(currentPixelX);
}
Dan S
  • 9,139
  • 3
  • 37
  • 48
  • Would you explain more the meaning of "make two pixels into anchor points that coorespond to a real life lat/long.Usually its (0,0) and (width,height) of a rectangular image." – eros Aug 17 '11 at 01:15
  • 1
    The idea is to bind 2 points on your image to real life latitude and longitude. Using the opposite corners (upper left and lower right) of the image will allow you to easily place an indicator where the user is at using a linear relation. – Dan S Aug 17 '11 at 17:28
  • For example, calculating distance from left divided by total left to right distance then using that as a percentage to mark the the position on the image. – Dan S Aug 17 '11 at 17:34
  • I see.. thanks, I got the binding 2 points. However, due to lack of knowledge.. I can't understand the "from left divided by total left to right distance then using that as a percentage to mark the the position". Would you add more about the percentage to mark the position. – eros Aug 18 '11 at 01:05
  • 1
    @eros, I have added some sample code to better express what that entire section means. You'll have to replicate it for the Y-axis to get the vertical position. – Dan S Aug 18 '11 at 01:39
  • From your idea, I got comprehensive example with actual,expected output and source code, testcase. Would you mind to take a look to this question -> http://stackoverflow.com/questions/7072400/android-how-to-mark-the-current-location-into-a-map-still-image-source-code – eros Aug 18 '11 at 05:58
  • Well, taking into consideration that a map controller is less of panning and zooming, and more of positioning and a lot of precision, your idea is sort of wrong. Also having in mind that there's already a lot of open source tools able to provide the required functionality, I'd say that there's no reason to walk the "nothing is invented" path. – Ilya Saunkin Aug 18 '11 at 06:33
  • @Dan S, where is the declaration of upperLeft & lowerRight? – eros Aug 19 '11 at 04:33
  • I got it. upperLeft & lowerRight are Location class. Please correct the below code for Y-axis to get the vertical position. `// Y-Axis - Vertical Position double hypotenuseY = lowerRight.distanceTo(current); double bearingY = lowerRight.bearingTo(current); double currentDistanceY = Math.cos(bearingY) * hypotenuseY; // "percentage to mark the position" double currentPixelY = (currentDistanceY / lowerRight.distanceTo(updateLeft) * Math.cos(lowerRight.bearingTo(upperLeft))) * mapWidth; moveIndicatorY(currentPixelY);` – eros Aug 19 '11 at 05:37
  • @Dan S, I created another question. would you take a look. http://stackoverflow.com/questions/7118001/how-to-compute-hypotenuse-and-bearing – eros Aug 19 '11 at 07:20
  • 1
    @eros, check your trignometry, its `Math.sin()` for Y. – Dan S Aug 19 '11 at 16:55