私は現在の位置を地図に表示するアプリケーションを作っていますが、このマップは画像です(Googleマップではありません)。どうやってやるの? Googleマップではない地図を使用します。Googleマップではないマップにユーザーの場所を表示するにはどうすればよいですか?
Googleマップの座標をこのマップと関連付けることができれば、これらの座標を取得するためにコアの場所を使用することができますか?
ideias?
私は現在の位置を地図に表示するアプリケーションを作っていますが、このマップは画像です(Googleマップではありません)。どうやってやるの? Googleマップではない地図を使用します。Googleマップではないマップにユーザーの場所を表示するにはどうすればよいですか?
Googleマップの座標をこのマップと関連付けることができれば、これらの座標を取得するためにコアの場所を使用することができますか?
ideias?
FAIの地球儀とWGS-84投影の両方の緯度/経度変換用に作成したクラスです。基本地理的なポイント(マップの中心など)で初期化し、そのポイントと他のポイントとの間の距離をメートルで計算します。マップのメーター/ピクセルの解像度を知っていれば、簡単にピクセル値に変換できます。
クラスについて詳しくは書かれていませんが、わかりました。別のクラスの鉱山(Vector)を使用していますが、CGPointで簡単に置き換えることができます。
注意:小規模な地図では機能しません。これは、大規模な地図(例えば、100km未満)を想定して、迅速な計算時間に最適化されています。
.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
画像をジオリファレンスする必要があります。
地図の投影パラメータを知る必要があります。
画像が経度/緯度プロジェクションでない場合は、マップで使用する座標と同じ投影に座標座標を投影する必要があります。
私は質問で混乱しています。緯度+経度座標はGoogleマップ固有のものではありません。あなたは同じページにGoogleマップとあなたのイメージの両方を持っていますか?または、イメージを表示したいだけですか? Googleはまた、このようなサービスを提供していますStatic Maps API
私はそのための方法私の質問でそれを言及し、Googleマップを使用したくない(つまりI私の地図を地理参照するためには、実際の地球の位置で自分の地図を参照しなければなりません。 – douglasd3
ありがとう!しかし、私は建物のような小規模な地図でそれを必要とする、適応する方法がありますか? – douglasd3
建物は実際には大規模な地図と呼ばれるものです(私は分かりますが、それは混乱します:-)私のコードは、100km未満の地図については完全に適用可能でなければなりません。 – fishinear