2012-01-05 72 views
1

我正在制作一个应用程序,它将显示地图中的当前位置,但此地图是一个图像(不是谷歌地图)。我怎样才能做到这一点?使用不是谷歌地图的地图。如何在不是Google地图的地图中显示某些用户位置?

我想知道是否有可能,以某种方式将谷歌地图坐标与我想使用的这张地图相关联,使用核心位置来获得这些坐标。

任何意识?

回答

0

这是我创建的用于FAI globe和WGS-84投影的纬度/经度转换的类。您使用基础地理点(例如:地图的中心)对其进行初始化,然后计算该点与其他点之间的距离(以米为单位)。如果您知道地图的米/像素分辨率,则可以轻松将其转换为像素值。

该课程没有很多文件,但我知道你可以弄明白。它使用了我的另一个类(Vector),但你应该可以用CGPoint轻松替换它。

CAVEAT:它不适用于小比例尺地图。对于假定大比例尺地图(比如:小于100公里)的快速计算时间进行了优化。

.h文件:

// 
// Earth.h 
// 
// Created by René Dekker on 01/10/2011. 
// Copyright 2011. All rights reserved. 
// 

#import <Foundation/Foundation.h> 
#import <CoreLocation/CoreLocation.h> 
#import "Vector.h" 

enum EarthModel { 
    EarthModelFAI = 0, 
    EarthModelWGS84 = 1 
}; 

@interface Earth : NSObject { 
    enum EarthModel theModel; 
    double theLongitudeScale; 
    double theLatitudeScale; 
    CLLocationCoordinate2D baseLocation; 
} 

@property CLLocationCoordinate2D baseLocation; 

+ (Earth *)earthModel:(enum EarthModel)model atLatitude:(double)baseLatitude; 
- (void) rebaseAtLatitude:(double)baseLatitude; 

+ (Earth *)earthAtLocation:(CLLocationCoordinate2D)location model:(enum EarthModel)model; 
- (void) rebaseAtLocation:(CLLocationCoordinate2D)location; 

- (Vector *) differenceBetween:(CLLocationCoordinate2D)first and:(CLLocationCoordinate2D)second; 
- (double) distanceBetween:(CLLocationCoordinate2D)first and:(CLLocationCoordinate2D)second; 
- (CLLocationCoordinate2D) addTo:(CLLocationCoordinate2D)location vector:(Vector *)vector; 
- (double) addToLongitude:(double)longitude distance:(double)distance; 
- (double) addToLatitude:(double)latitude distance:(double)distance; 

- (Vector *) vectorFromBase:(CLLocationCoordinate2D)location; 
- (double) distanceFromBase:(CLLocationCoordinate2D)location; 
- (CLLocationCoordinate2D) addToBase:(Vector *)vector; 

@end 

.m文件:

// 
// Earth.m 
// 
// Created by René Dekker on 01/10/2011. 
// Copyright 2011. All rights reserved. 
// 
// The information and formulas used in the WGS84 computations come mainly from: 
// http://en.wikipedia.org/wiki/World_Geodetic_System 
// http://en.wikipedia.org/wiki/Meridian_arc#Meridian_distance_on_the_ellipsoid 
// http://www.holoscenes.com/cgi-bin/moin.cgi/Ellipsoid 
// http://www.movable-type.co.uk/scripts/gis-faq-5.1.html 
// http://williams.best.vwh.net/avform.htm 
// 

#import "Earth.h" 

#define WGS_EQUATOR_R 6378137.0 
#define WGS_POLAR_R  6356752.314245 
#define F    (1/298.257223563) 
#define E2    (F * (2 - F)) 
#define FAI_R   6371000 

@implementation Earth 

double modTo(double x, double lower, double upper) 
{ 
    double range = upper - lower; 
    double result = fmod(x - lower, range); 
    if (result < 0) { 
     result += range; 
    } 
    return result + lower; 
} 


- (void) rebaseAtLatitude:(double)baseLatitude 
{ 
    baseLatitude *= PI_DEGREE; 
    if (theModel == EarthModelWGS84) { 
     double sinLat = sin(baseLatitude); 
     double factor = sqrt(1 - E2*sinLat*sinLat); 
     theLatitudeScale = PI_DEGREE * WGS_EQUATOR_R * (1-E2)/pow(factor, 3); 
     theLongitudeScale = PI_DEGREE * WGS_EQUATOR_R * cos(baseLatitude)/factor; 
    } else { 
     theLatitudeScale = PI_DEGREE * FAI_R; 
     theLongitudeScale = PI_DEGREE * FAI_R * cos(baseLatitude); 
    } 
} 

- (void) rebaseAtLocation:(CLLocationCoordinate2D)location 
{ 
    baseLocation = location; 
    [self rebaseAtLatitude:location.latitude]; 
} 

- (CLLocationCoordinate2D) baseLocation 
{ 
    return baseLocation; 
} 

- (void) setBaseLocation:(CLLocationCoordinate2D)location 
{ 
    baseLocation = location; 
    [self rebaseAtLatitude:location.latitude]; 
} 

- (Earth *) initWithModel:(enum EarthModel)model atLocation:(CLLocationCoordinate2D)location 
{ 
    if (!(self = [super init])) { 
     return nil; 
    } 
    theModel = model; 
    [self rebaseAtLocation:location]; 
    return self; 
} 

+ (Earth *)earthModel:(enum EarthModel)model atLatitude:(double)baseLatitude 
{ 
    CLLocationCoordinate2D location = CLLocationCoordinate2DMake(baseLatitude, 0); 
    return [[[Earth alloc] initWithModel:model atLocation:location] autorelease]; 
} 

+ (Earth *)earthAtLocation:(CLLocationCoordinate2D)location model:(enum EarthModel)model 
{ 
    return [[[Earth alloc] initWithModel:model atLocation:location] autorelease]; 
} 

- (Vector *) differenceBetween:(CLLocationCoordinate2D)first and:(CLLocationCoordinate2D)second 
{ 
    double dx = modTo(first.longitude - second.longitude, -180, 180) * theLongitudeScale; 
    double dy = (first.latitude - second.latitude) * theLatitudeScale; 
    return [Vector withX:dx y:dy]; 
} 

- (double) distanceBetween:(CLLocationCoordinate2D)first and:(CLLocationCoordinate2D)second 
{ 
    double dx = modTo(first.longitude - second.longitude, -180, 180) * theLongitudeScale; 
    double dy = (first.latitude - second.latitude) * theLatitudeScale; 
    return hypot(dx, dy); 
} 

- (CLLocationCoordinate2D) addTo:(CLLocationCoordinate2D)location vector:(Vector *)vector 
{ 
    location.latitude += vector.y/theLatitudeScale; 
    location.longitude += modTo(vector.x/theLongitudeScale, -180, 180); 
    return location; 
} 

- (Vector *) vectorFromBase:(CLLocationCoordinate2D)location 
{ 
    return [self differenceBetween:location and:baseLocation]; 
} 

- (double) distanceFromBase:(CLLocationCoordinate2D)location 
{ 
    return [self distanceBetween:location and:baseLocation]; 
} 

- (CLLocationCoordinate2D) addToBase:(Vector *)vector 
{ 
    return [self addTo:baseLocation vector:vector]; 
} 

- (double) addToLongitude:(double)longitude distance:(double)distance 
{ 
    return modTo(longitude + distance/theLongitudeScale, -180, 180); 
} 

- (double) addToLatitude:(double)latitude distance:(double)distance 
{ 
    return latitude + distance/theLatitudeScale; 
} 

- (NSString *) description 
{ 
    return NSStringFromCLLocationCoordinate2D(baseLocation); 
} 

@end 
+0

谢谢!但我需要小规模地图,就像建筑物一样,有一种适应的方法? – douglasd3 2012-01-11 12:14:11

+0

建筑物实际上就是所谓的大比例尺地图(我知道,它令人困惑:-)我的代码应该完全适用于任何小于100公里的地图。 – fishinear 2012-01-11 15:48:42

1
  1. 您的图片必须是地理参考。您将不得不知道地图的投影参数。

  2. 如果图像不在经度/纬度投影中,您将不得不投影坐标核心位置提供给您的地图使用的相同投影。

0

我对这个问题感到困惑;纬度+经度坐标并不是Google地图唯一的。你会在同一页面上同时拥有谷歌地图和图片吗?或者你只是想显示一个图像? Google还提供使用Static Maps API

+0

我不希望使用谷歌地图,我在我的问题提到它,因为它的方式(即我认为)地理参考我的地图,我必须参考我的地图真实的地球位置,在全球使用核心位置数据。 – douglasd3 2012-01-11 12:16:25

相关问题