GoogleMap:
5985 ワード
https://developers.google.com/maps/documentation/ios-sdk/
1.
Podfile:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.1' pod 'GoogleMaps'
2.
iOS 9とXcode 7を使用する場合、アプリケーションは
Google Maps SDK for iOSが使用するURLアーキテクチャを宣言するには、次のコードを追加します.
1.
Podfile:
source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.1' pod 'GoogleMaps'
2.
iOS 9とXcode 7を使用する場合、アプリケーションは
Info.plist
ファイルにスキーマを指定して、開くURLスキーマを宣言します.ユーザーが地図上のGoogleロゴをクリックすると、Google Maps SDK for iOSがGoogle Mapsモバイルアプリケーションを開くので、アプリケーションに関連するURLアーキテクチャを宣言する必要があります.Google Maps SDK for iOSが使用するURLアーキテクチャを宣言するには、次のコードを追加します.
Info.plist
:
Xcode :
3.
, 。 Info.plist
ファイルで、「 」または「 」の を します.NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
サイト・セレクタの は、「 」 を するだけで ですが、アプリケーションの の に して「 に」 を する がある があります. キーに を し、ロケーションサービスが な をユーザーに します. :
4:key
5.
const double a = 6378245.0;
const double ee = 0.00669342162296594323;
+ (CLLocation *)transformToMars:(CLLocation *)location {
//
if ([[self class] outOfChina:location]) {
return location;
}
double dLat = [[self class] transformLatWithX:location.coordinate.longitude - 105.0 y:location.coordinate.latitude - 35.0];
double dLon = [[self class] transformLonWithX:location.coordinate.longitude - 105.0 y:location.coordinate.latitude - 35.0];
double radLat = location.coordinate.latitude / 180.0 * M_PI;
double magic = sin(radLat);
magic = 1 - ee * magic * magic;
double sqrtMagic = sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * M_PI);
dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * M_PI);
return [[CLLocation alloc] initWithLatitude:location.coordinate.latitude + dLat longitude:location.coordinate.longitude + dLon];
}
+ (BOOL)outOfChina:(CLLocation *)location {
if (location.coordinate.longitude < 72.004 || location.coordinate.longitude > 137.8347) {
return YES;
}
if (location.coordinate.latitude < 0.8293 || location.coordinate.latitude > 55.8271) {
return YES;
}
return NO;
}
+ (double)transformLatWithX:(double)x y:(double)y {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x));
ret += (20.0 * sin(6.0 * x * M_PI) + 20.0 * sin(2.0 * x * M_PI)) * 2.0 / 3.0;
ret += (20.0 * sin(y * M_PI) + 40.0 * sin(y / 3.0 * M_PI)) * 2.0 / 3.0;
ret += (160.0 * sin(y / 12.0 * M_PI) + 320 * sin(y * M_PI / 30.0)) * 2.0 / 3.0;
return ret;
}
+ (double)transformLonWithX:(double)x y:(double)y {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(fabs(x));
ret += (20.0 * sin(6.0 * x * M_PI) + 20.0 * sin(2.0 * x * M_PI)) * 2.0 / 3.0;
ret += (20.0 * sin(x * M_PI) + 40.0 * sin(x / 3.0 * M_PI)) * 2.0 / 3.0;
ret += (150.0 * sin(x / 12.0 * M_PI) + 300.0 * sin(x / 30.0 * M_PI)) * 2.0 / 3.0;
return ret;
}