Android: How To: display a map (still image file) with a moving current location pointer

独自空忆成欢 提交于 2019-11-27 06:30:36

问题


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.


回答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);
}


来源:https://stackoverflow.com/questions/7062115/android-how-to-display-a-map-still-image-file-with-a-moving-current-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!