[英]How can i show user's current country when user denies location access in Google map?
[英]How can i show some user location in a map that is not google maps?
我正在制作一個將在地圖上顯示當前位置的應用程序,但是此地圖是圖像(不是Google地圖)。 我怎樣才能做到這一點? 使用不是Google地圖的地圖。
我想知道是否有可能以某種方式將Google地圖坐標與我要使用的這張地圖相關聯,並使用核心位置獲取這些坐標。
有什么想法嗎?
您的圖片必須經過地理參考。
您將必須知道地圖的投影參數。
如果圖像不在經度/緯度投影中,則必須將核心位置提供的坐標投影到地圖使用的相同投影中。
我對這個問題感到困惑; 緯度+經度坐標並非Google地圖唯一。 您會在同一頁面上同時擁有Google地圖和圖片嗎? 還是只想顯示圖像? Google還使用Static Maps API提供此類服務
這是我為FAI地球儀和WGS-84投影的緯度/經度轉換創建的一個類。 您可以使用基本地理點(例如:地圖的中心)進行初始化,並且它將計算該點與其他點之間的距離(以米為單位)。 如果您隨后知道地圖的米/像素分辨率,則可以輕松地將其轉換為像素值。
該課程沒有很多文檔,但是我知道您可以弄清楚。 它使用了我的另一類(向量),但是您應該能夠輕松地用CGPoint替換它。
注意:它不適用於小比例尺地圖。 假設有大比例尺地圖(例如,小於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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.