简体   繁体   English

如何在非Google地图的地图中显示某些用户位置?

[英]How can i show some user location in a map that is not google maps?

I'm making an app that will show the current location in a map, but this map is a image (not google maps). 我正在制作一个将在地图上显示当前位置的应用程序,但是此地图是图像(不是Google地图)。 How can i do that? 我怎样才能做到这一点? Use a map that is not google maps. 使用不是Google地图的地图。

I'm wondering if is possible, somehow, to relate the google maps coordinates with this map i want to use, using core location to get these coordinates. 我想知道是否有可能以某种方式将Google地图坐标与我要使用的这张地图相关联,并使用核心位置获取这些坐标。

Any ideias? 有什么想法吗?

  1. Your image will have to be geo-referenced. 您的图片必须经过地理参考。

  2. You will have to know the projection parameters of the map. 您将必须知道地图的投影参数。

  3. If the image is not in longitude/latitude projection you will have to project the coordinates core location provides to the same projection your map uses. 如果图像不在经度/纬度投影中,则必须将核心位置提供的坐标投影到地图使用的相同投影中。

I'm confused by the question; 我对这个问题感到困惑; latitude + longitude coordinates aren't unique to Google Maps. 纬度+经度坐标并非Google地图唯一。 Will you have both a google map and your image on the same page? 您会在同一页面上同时拥有Google地图和图片吗? Or are you just wanting to display an image? 还是只想显示图像? Google also provide such a service using the Static Maps API Google还使用Static Maps API提供此类服务

Here is a class I created for latitude/longitude conversions for both FAI globe and WGS-84 projections. 这是我为FAI地球仪和WGS-84投影的纬度/经度转换创建的一个类。 You initialize it with a base geographic point (say: the center of your map), and it will compute distance in meters between that point and other points. 您可以使用基本地理点(例如:地图的中心)进行初始化,并且它将计算该点与其他点之间的距离(以米为单位)。 If you then know the meters/pixel resolution of your map, you can easily convert it to pixel values. 如果您随后知道地图的米/像素分辨率,则可以轻松地将其转换为像素值。

The class is not very much documented, but I know you can figure it out. 该课程没有很多文档,但是我知道您可以弄清楚。 It uses another class of mine (Vector), but you should be able to replace that with CGPoint easily. 它使用了我的另一类(向量),但是您应该能够轻松地用CGPoint替换它。

CAVEAT: it will not work with small scale maps. 注意:它不适用于小比例尺地图。 It is optimized for quick computing time assuming a large scale map (say: smaller than 100km across). 假设有大比例尺地图(例如,小于100公里的地图),则可优化其快速计算时间。

The .h file: .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

The .m file: .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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户拒绝在Google地图中访问位置时,如何显示用户的当前国家/地区? - How can i show user's current country when user denies location access in Google map? Google Maps iOS SDK:如何在用户的位置上启动地图 - Google Maps iOS SDK: How to start map on user's location 如何在Google Maps iOS SDK上显示用户位置 - How to show user location on Google Maps iOS SDK 如何将Google地图显示为WebView? - How can I show Google Maps into a WebView? 谷歌地图 - 如何找出用户的位置并在 Swift 中显示从该位置到目的地的路线? - Google maps - how to find out user's location and show the route from that location to the destination point in Swift? 如何在 Xcode 的地图中显示我当前的位置? - How can I show my current location in maps in Xcode? 无法使用“google_maps_flutter”插件在 Flutter 中显示当前用户位置 - Can't show current user location in Flutter using 'google_maps_flutter' plugin 在Google地图上显示和隐藏用户默认位置标记 - Show and hide user default location marker on Google Maps 如何在Google Maps App中从另一个位置显示当前位置? - How to show the current location from another location in google maps App? 如何在自定义地图上显示用户位置? - How to show user location on custom map?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM