开发者

What Android API's should I use? Simple map application

Would I use the standard map api? The reason I ask is that I'd like the map to be a custom image I've made in photoshop of my campus. I found that someone at another university did something similar. How would I make something like this?

http开发者_开发技巧://s3.appbrain.com/screen?id=2110362890445967243&i=1

Would something like this have to be offline? Could it still give your current geo location? Thanks.


I've done this in the past, it's not too hard.

Forget the Map API. You just need a accurately scaled image of the area you want on the map.

You just need the longitude and latitudes of the four corners and the width and height of the image. Once you have that, you can do some relatively simple math to convert the phones GPS coordinates to X, Y points on the image.

I did this with a cartoon image of Grant Park in Chicago for the Android Lollapalooza app in 2010. My problem was actually slightly more difficult, because the map was squished vertically and slightly shifted a few degrees, so my math add to accomodate for that. If you are just creating a straight overhead shot, it should be pretty easy.

Here is a utility function I used to convert from Long/Lat values to a point. It won't be exactly what you need because it had specific values that where associated with the image I was using, but might get you going in the right direction.

public static PointF GPSToMap(double latitude, double longitude, 
        double minLat, double minLon, double maxLat, double maxLon,
        long width, long height, String xExpr, String yExpr)
{
    double numerator;
    double denominator;

    numerator = latitude - minLat;
    denominator = maxLat - minLat;
    double x = width - ((numerator/denominator*width));
    numerator = longitude - minLon;
    denominator = maxLon - minLon;
    double y = height - ((numerator/denominator*height));

    Double dblX = new Double(x+(y*0.434026)-((x-100)*0.180));
    Double dblY = new Double(y*0.99);

    MathEval math = new MathEval();

    dblY += math.evaluate(yExpr); //-40
    dblX += math.evaluate(xExpr); //-15
    return new PointF(dblX.floatValue(), dblY.floatValue());
}


Start here:

http://developer.android.com/guide/tutorials/views/hello-mapview.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜