iphone照片经纬度坐标转换经纬度

主题 : 高德地图经纬度转坐标问题
级别: 新手上路
可可豆: 43 CB
威望: 43 点
在线时间: 22(时)
发自: Web Page
来源于&&分类
高德地图经纬度转坐标问题&&&
self.view里添加了一个全屏的MAMapView,并传入了一个已知的经纬度,通过- (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate animated:(BOOL)animated将其设为地图的中心点,现在想通过- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view获取到该经纬度对应的在self.view坐标系统里的坐标,我觉得应该返回的self.view的中心点的坐标,结果返回的是{, 314530},请大家帮忙看下那块儿写的有问题,代码如下- (void)loadView{ self.view = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease]; self.view.backgroundColor = [UIColor whiteColor]; _mapView = [[[MAMapView alloc] initWithFrame:self.view.bounds] autorelease]; _mapView.zoomLevel = 18; _mapView.delegate =    [self.view addSubview:_mapView];}- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    [_mapView setCenterCoordinate:_coordinate animated:YES]; CGPoint point = [_mapView convertCoordinate:_coordinate toPointToView:self.view]; NSLog(@&%@&, NSStringFromCGPoint(point));}
级别: 侠客
UID: 358994
可可豆: 250 CB
威望: 173 点
在线时间: 840(时)
发自: Web Page
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版iOS中地图经纬度坐标转换 - 简书
iOS中地图经纬度坐标转换
常用地图坐标系介绍:
WGS-84:是国际标准,GPS坐标(Google Earth使用、或者GPS模块)
GCJ-02:中国坐标偏移标准,Google地图、高德、腾讯使用
BD-09 :百度坐标偏移标准,Baidu地图使用
我们经常在常用的这几种地图中进行坐标转换,或用于第三方地图的导航,或用于后台下发地址的打点等等场景。虽然百度和高德都提供相应的api,但是他们都只提供向自家坐标系转化的api,需要连网请求才能得到转化后的结果。(前提还得申请他们开放平台的appKey)
下面附上百度地图转换为自家经纬度坐标的链接:
下面附上高德地图转换为自家经纬度坐标的链接:
下面提供一个无联网环境下的坐标转化算法,
话不多说,直接上源代码:
YQLocationTransform.h文件
#import &Foundation/Foundation.h&
@interface YQLocationTransform : NSObject
@property (nonatomic, assign)
@property (nonatomic, assign)
- (id)initWithLatitude:(double)latitude andLongitude:(double)
WGS-84:是国际标准,GPS坐标(Google Earth使用、或者GPS模块)
GCJ-02:中国坐标偏移标准,Google Map、高德、腾讯使用
BD-09 :百度坐标偏移标准,Baidu Map使用
#pragma mark - 从GPS坐标转化到高德坐标
- (id)transformFromGPSToGD;
#pragma mark - 从高德坐标转化到百度坐标
- (id)transformFromGDToBD;
#pragma mark - 从百度坐标到高德坐标
- (id)transformFromBDToGD;
#pragma mark - 从高德坐标到GPS坐标
- (id)transformFromGDToGPS;
#pragma mark - 从百度坐标到GPS坐标
- (id)transformFromBDToGPS;
YQLocationTransform.m文件
#import "YQLocationTransform.h"
#import &CoreLocation/CoreLocation.h&
static const double a = ;
static const double ee = 0.;
static const double pi = M_PI;
static const double xPi = M_PI
* 3000.0 / 180.0;
@implementation YQLocationTransform
- (id)initWithLatitude:(double)latitude andLongitude:(double)longitude {
if (self = [super init]) {
self.latitude =
self.longitude =
- (id)transformFromGPSToGD {
CLLocationCoordinate2D coor = [ECLocationTransform transformFromWGSToGCJ:CLLocationCoordinate2DMake(self.latitude, self.longitude)];
return [[ECLocationTransform alloc] initWithLatitude:coor.latitude andLongitude:coor.longitude];
- (id)transformFromGDToBD {
CLLocationCoordinate2D coor = [ECLocationTransform transformFromGCJToBaidu:CLLocationCoordinate2DMake(self.latitude, self.longitude)];
return [[ECLocationTransform alloc] initWithLatitude:coor.latitude andLongitude:coor.longitude];
- (id)transformFromBDToGD {
CLLocationCoordinate2D coor = [ECLocationTransform transformFromBaiduToGCJ:CLLocationCoordinate2DMake(self.latitude, self.longitude)];
return [[ECLocationTransform alloc] initWithLatitude:coor.latitude andLongitude:coor.longitude];
- (id)transformFromGDToGPS {
CLLocationCoordinate2D coor = [ECLocationTransform transformFromGCJToWGS:CLLocationCoordinate2DMake(self.latitude, self.longitude)];
return [[ECLocationTransform alloc] initWithLatitude:coor.latitude andLongitude:coor.longitude];
- (id)transformFromBDToGPS {
//先把百度转化为高德
CLLocationCoordinate2D start_coor = [ECLocationTransform transformFromBaiduToGCJ:CLLocationCoordinate2DMake(self.latitude, self.longitude)];
CLLocationCoordinate2D end_coor = [ECLocationTransform transformFromGCJToWGS:CLLocationCoordinate2DMake(start_coor.latitude, start_coor.longitude)];
return [[ECLocationTransform alloc] initWithLatitude:end_coor.latitude andLongitude:end_coor.longitude];
+ (CLLocationCoordinate2D)transformFromWGSToGCJ:(CLLocationCoordinate2D)wgsLoc {
CLLocationCoordinate2D adjustL
if([self isLocationOutOfChina:wgsLoc]) {
adjustLoc = wgsL
double adjustLat = [self transformLatWithX:wgsLoc.longitude - 105.0 withY:wgsLoc.latitude - 35.0];
double adjustLon = [self transformLonWithX:wgsLoc.longitude - 105.0 withY:wgsLoc.latitude - 35.0];
long double radLat = wgsLoc.latitude / 180.0 *
long double magic = sin(radLat);
magic = 1 - ee * magic *
long double sqrtMagic = sqrt(magic);
adjustLat = (adjustLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
adjustLon = (adjustLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi);
adjustLoc.latitude = wgsLoc.latitude + adjustL
adjustLoc.longitude = wgsLoc.longitude + adjustL
return adjustL
+ (double)transformLatWithX:(double)x withY:(double)y {
double lat = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x));
lat += (20.0 * sin(6.0 * x * pi) + 20.0 *sin(2.0 * x * pi)) * 2.0 / 3.0;
lat += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0;
lat += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0;
+ (double)transformLonWithX:(double)x withY:(double)y {
double lon = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(fabs(x));
lon += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
lon += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0;
lon += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0;
+ (CLLocationCoordinate2D)transformFromGCJToBaidu:(CLLocationCoordinate2D)p {
long double z = sqrt(p.longitude * p.longitude + p.latitude * p.latitude) + 0.00002 * sqrt(p.latitude * pi);
long double theta = atan2(p.latitude, p.longitude) + 0.000003 * cos(p.longitude * pi);
CLLocationCoordinate2D geoP
geoPoint.latitude
= (z * sin(theta) + 0.006);
geoPoint.longitude = (z * cos(theta) + 0.0065);
return geoP
+ (CLLocationCoordinate2D)transformFromBaiduToGCJ:(CLLocationCoordinate2D)p {
double x = p.longitude - 0.0065, y = p.latitude - 0.006;
double z = sqrt(x * x + y * y) - 0.00002 * sin(y * xPi);
double theta = atan2(y, x) - 0.000003 * cos(x * xPi);
CLLocationCoordinate2D geoP
geoPoint.latitude
= z * sin(theta);
geoPoint.longitude = z * cos(theta);
return geoP
+ (CLLocationCoordinate2D)transformFromGCJToWGS:(CLLocationCoordinate2D)p {
double threshold = 0.00001;
// The boundary
double minLat = p.latitude - 0.5;
double maxLat = p.latitude + 0.5;
double minLng = p.longitude - 0.5;
double maxLng = p.longitude + 0.5;
double delta = 1;
int maxIteration = 30;
// Binary search
while(true) {
CLLocationCoordinate2D leftBottom
= [[self class] transformFromWGSToGCJ:(CLLocationCoordinate2D){.latitude = minLat,.longitude = minLng}];
CLLocationCoordinate2D rightBottom = [[self class] transformFromWGSToGCJ:(CLLocationCoordinate2D){.latitude = minLat,.longitude = maxLng}];
CLLocationCoordinate2D leftUp
= [[self class] transformFromWGSToGCJ:(CLLocationCoordinate2D){.latitude = maxLat,.longitude = minLng}];
CLLocationCoordinate2D midPoint
= [[self class] transformFromWGSToGCJ:(CLLocationCoordinate2D){.latitude = ((minLat + maxLat) / 2),.longitude = ((minLng + maxLng) / 2)}];
delta = fabs(midPoint.latitude - p.latitude) + fabs(midPoint.longitude - p.longitude);
if(maxIteration-- &= 0 || delta &= threshold) {
return (CLLocationCoordinate2D){.latitude = ((minLat + maxLat) / 2),.longitude = ((minLng + maxLng) / 2)};
if(isContains(p, leftBottom, midPoint)) {
maxLat = (minLat + maxLat) / 2;
maxLng = (minLng + maxLng) / 2;
} else if(isContains(p, rightBottom, midPoint)) {
maxLat = (minLat + maxLat) / 2;
minLng = (minLng + maxLng) / 2;
} else if(isContains(p, leftUp, midPoint)) {
minLat = (minLat + maxLat) / 2;
maxLng = (minLng + maxLng) / 2;
minLat = (minLat + maxLat) / 2;
minLng = (minLng + maxLng) / 2;
#pragma mark - 判断某个点point是否在p1和p2之间
static bool isContains(CLLocationCoordinate2D point, CLLocationCoordinate2D p1, CLLocationCoordinate2D p2) {
return (point.latitude &= MIN(p1.latitude, p2.latitude) && point.latitude &= MAX(p1.latitude, p2.latitude)) && (point.longitude &= MIN(p1.longitude,p2.longitude) && point.longitude &= MAX(p1.longitude, p2.longitude));
#pragma mark - 判断是不是在中国
+ (BOOL)isLocationOutOfChina:(CLLocationCoordinate2D)location {
if (location.longitude & 72.004 || location.longitude & 137.8347 || location.latitude & 0.8293 || location.latitude & 55.8271)
return YES;
return NO;
用法如下:
YQLocationTransform *beforeLocation = [[YQLocationTransform alloc] initWithLatitude:22.549522 andLongitude:113.947933];
//百度转化为GPS
YQLocationTransform *afterLocation = [beforeLocation transformFromBDToGPS];
NSLog(@"转化后:%f, %f", afterLocation.latitude, afterLocation.longitude);
talk is cheap, show me the code
1 序: 很多新接触GIS的人员对地图投影以及坐标系统很难理解,甚至做GIS开发做了好几年的人也有这方面的疑惑,地球仪式的地图是如何变成纸上的平面地图的?平面的二维地图是如何在三维GIS里面进行展示的,因为三维地球里面的地图也是用的二维的地图瓦片,这里对投影的内容进行一下简...
众所周知地球是一个不规则椭圆体,GIS中的坐标系定义由基准面和地图投影两组参数确定,而基准面的定义则由特定椭球体及其对应的转换参数确定。 基准面是利用特定椭球体对特定地区地球表面的逼近,因此每个国家或地区均有各自的基准面。基准面是在椭球体基础上建立的,椭球体可以对应多个基准...
一、各个坐标系的概况 众所周知地球是一个不规则椭圆体,GIS中的坐标系定义由基准面和地图投影两组参数确定,而基准面的定义则由特定椭球体及其对应的转换参数确定。 基准面是利用特定椭球体对特定地区地球表面的逼近,因此每个国家或地区均有各自的基准面。基准面是在椭球体基础上建立的,...
常见的坐标系有三种: 1、地球坐标(WGS84,国际公认坐标), 2、火星坐标(GCJ02,国家标准,适用于高德百度地图大陆+港澳部分、Google地图大陆部分), 3、百度坐标(BD09,适用于百度地图大陆+港澳台部分)。坐标系需要和地图关连才有意义,只有正确匹配地图坐标...
该文章属于&简书 — 刘小壮&原创,转载请注明: &简书 — 刘小壮& http://www.jianshu.com/p/4a 本人现就职于国内某地图导航公司,这篇文章是我前段时间在公司组织技术分享的一个PPT,文章内容也主要由这个PPT的内容为主,通过...
眼睛一闭一睁,一周又过去啦! 在过去的一周里,跨境电商领域都发生了哪些大事呢?快跟聚考拉一起来看看吧! 亚马逊悄然推出网红营销项目,目前仍在测试阶段 像Instagram和YouTube等社交媒体网红,经常与品牌合作或者实行联盟营销,在社交媒体上宣传产品。 现在亚马逊也开始...
大雨(冬至节) 一向讨厌雨天的我,今天也没有例外。 下雨天楼下大厅全是水,每跑一步都要设想下一秒会摔个狗吃屎的后怕。烦透了这种鬼天气,想着就刷个3公里就回去。每到这种天,小区里点外卖的也多了起来。看着来往一个接着一个顶着大雨送外卖的工作者,心情越发不好了...
人生重要的不是所站的位置,而是所朝的方向。 诚然,有些人一出生就获得了很大的财富,比如美貌,比如家世,比如无尽的呵护和爱。也有人除了继承祖上的基因,一无所有。大多数人应该都差不多,父母的爱,愉快的童年,顺其自然的成家立业,平凡地度过一年又一年。 仰望着多金人类出入高档餐厅,...
世界上总有很多事情不那么尽如人意,但在之前,你是否尽全力。 小夏是一个很懦弱的人。 他喜欢一个女孩,却一直不敢表白。因为女孩很优秀,长的漂亮,性格温柔,说话的时候总是微微笑着。而他呢,长得很普通,成绩一般,性格软弱,说话的时候不敢看人。 小夏一直认为自己配不上她,即使表白,...
眼儿媚《龙城之行有感》 女侠方舟/文 龙城今夕竞风流,满眼擎天楼。 摧烟风起,落尘帘下,无奈清休。 小雨午间弄轻柔,且又酿春愁。 繁花影里,九龙湖畔,波浪心头。ios输入地址得出经纬度
ios输入地址得出经纬度
CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
[myGeocoder geocodeAddressString:_searchBar.text completionHandler:^(NSArray *placemarks, NSError *error) {
if ([placemarks count] & 0 && error == nil) {
CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];
NSLog(@&%f&,firstPlacemark.location.coordinate.latitude);
NSLog(@&%f&,firstPlacemark.location.coordinate.longitude);
else if ([placemarks count] == 0 && error == nil) {
NSLog(@&Found no placemarks.&);
else if (error != nil) {
NSLog(@&An error occurred = %@&, error); } }];6.8k 人阅读
标签:至少1个,最多5个
一、坐标体系
首先我们要明白,开发者能接触到哪些坐标体系呢?
第一种分类:
GPS,WGS-84,原始坐标体系。一般用国际标准的GPS记录仪记录下来的坐标,
都是GPS的坐标。很可惜,在中国,任何一个地图产品都不允许使用GPS坐标,
据说是为了保密。GPS坐标形式如图,度分秒形式的经纬度。
GCJ-02,国测局02年发布的坐标体系。又称“火星坐标”。
在中国,必须至少使用GCJ-02的坐标体系。比如谷歌,腾讯,高德都在
用这个坐标体系。GCJ-02也是国内最广泛使用的坐标体系。
其他坐标体系。一般都是由GCJ-02进过偏移算法得到的。
这种体系就根据每个公司的不同,坐标体系都不一样了。比如,
百度和搜狗就使用自己的坐标体系,与其他坐标体系不兼容。
第二种分类:
首先明白,所有坐标体系的原点,都是非洲。
经纬度。这个是球面坐标,对于北京来说,就是(116.961)这
样的坐标。比如腾讯、高德、百度都是这样的经纬度坐标。
谷歌是经纬度顺序写反的经纬度坐标。如果是度分秒坐标,需要进行转换
,才能得到这样的经纬度坐标。详见坐标转换。
墨卡托坐标。平面坐标,相当于是直线距离,数字一般都比较大,像这样的。
(26.)墨卡托坐标,
主要用于程序的后台计算。直线距离嘛,加加减减几乎计算方便。
搜狗地图API就是直接使用的墨卡托坐标。
二、坐标转换
在各种web端平台,或者高德、腾讯、百度上取到的坐标,都不是GPS坐标,
都是GCJ-02坐标,或者自己的偏移坐标系。
比如,你在谷歌地图API,高德地图API,腾讯地图API上取到的,
都是GCJ-02坐标,他们三家都是通用的,也适用于大部分地图API产品,
以及他们的地图产品。
例外,百度API上取到的,是BD-09坐标,只适用于百度地图相关产品。
例外,搜狗API上取到的,是搜狗坐标,只适用于搜狗地图相关产品。
例外,谷歌地球,google earth上取到的,是GPS坐标,
而且是度分秒形式的经纬度坐标。在国内不允许使用。必须转换为GCJ-02坐标。
度分秒坐标转换为经纬度
比如,在GPS记录仪,或者google earth上采集到的是39°31'20.51,那么应该这样换算,31分就是31/60度,20.51秒就是20.51/3600度,结果就是39 + 31/60 + 20.51/3600 度。
GPS转换为GCJ-02坐标
谷歌,高德,腾讯的地图API官网上,都不直接提供这样的坐标转换。如果要得到GCJ-02坐标,最好在他们的地图上直接取点,或者通过地址解析得到。不过,在网上搜到了这样的接口,该接口的type=1就是GPS转到GCJ-02的墨卡托坐标。请大家对接口保密。详见:
GCJ-02与BD-09之间互转
国测局GCJ-02坐标体系(谷歌、高德、腾讯),与百度坐标BD-09体系的转换,我今天想说的就是这个,后面有相关代码!
4、经纬纬度转成墨卡托
网上也有详细讲解:(大家发现没,高德是api,腾讯和百度是mapapi,说明什么?)
三、坐标偏移
如果您的坐标在转换之后,还有偏移,那么考虑以下几个方面。
A、原始坐标系弄错,比如以为自己是GPS坐标,但其实已经是GCJ-02坐标。
解决方案:请确保采集到的数据是哪个坐标体系,需要转换到哪个坐标系,再进行坐标转换。
B、原始坐标准确度不够
解决方案:如果您是GPS坐标,请确保采集GPS数据时,搜到至少4颗以上的卫星。并且GPS数据准不准,还取决于周围建筑物的高度,越高越不准,因为有遮挡。
如果本来就是GCJ-02坐标,在不同地图放大级别的时候,看到的地方可能不一样。比如你在地图级别4(国家)取到的坐标,放大到地图12级(街道)时,坐标就偏了。请确保在地图最大放大级别时,拾取坐标。
C、度分秒的概念混淆
比如,在google earth上采集到的是39°31'20.51,那么应该这样换算,31分就是31/60度,20.51秒就是20.51/3600度,结果就是39 + 31/60 + 20.51/3600 度。
D、经纬度顺序写反了
有些公司(比如高德,百度,腾讯)是先经度,再纬度,即Point(lng lat)。但谷歌坐标的顺序恰好相反,是(lat lng)。
百度地图坐标与苹果自带地图经纬度之间的相互转换方法:
/// 百度坐标转高德坐标
+ (CLLocationCoordinate2D)GCJ02FromBD09:(CLLocationCoordinate2D)coor
CLLocationDegrees x_pi = 3.79324 * 3000.0 / 180.0;
CLLocationDegrees x = coor.longitude - 0.0065, y = coor.latitude - 0.006;
CLLocationDegrees z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
CLLocationDegrees theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
CLLocationDegrees gg_lon = z * cos(theta);
CLLocationDegrees gg_lat = z * sin(theta);
return CLLocationCoordinate2DMake(gg_lat, gg_lon);
// 高德坐标转百度坐标
+ (CLLocationCoordinate2D)BD09FromGCJ02:(CLLocationCoordinate2D)coor
CLLocationDegrees x_pi = 3.79324 * 3000.0 / 180.0;
CLLocationDegrees x = coor.longitude, y = coor.
CLLocationDegrees z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
CLLocationDegrees theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
CLLocationDegrees bd_lon = z * cos(theta) + 0.0065;
CLLocationDegrees bd_lat = z * sin(theta) + 0.006;
return CLLocationCoordinate2DMake(bd_lat, bd_lon);
JZLocationConverter:
python版本
# -*- coding: utf-8 -*-
import math
x_pi = 3.79324 * 3000.0 / 180.0
def bd_encrypt(gg):
x = gg["gg_lon"]
y = gg["gg_lat"]
z = math.sqrt(x * x + y * y) + 0.00002 * math.sin(y * x_pi)
theta = math.atan2(y, x) + 0.000003 * math.cos(x * x_pi)
bd_lon = z * math.cos(theta) + 0.0065
bd_lat = z * math.sin(theta) + 0.006
return {"bd_lon":bd_lon, "bd_lat":bd_lat}
def bd_decrypt(bd):
x = bd["bd_lon"] - 0.0065
y = bd["bd_lat"] - 0.006;
z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi);
theta = atan2(y, x) - 0.000003 * cos(x * x_pi);
gg_lon = z * cos(theta);
gg_lat = z * sin(theta);
return {"gg_lon":gg_lon, "gg_lat":gg_lat}
0 收藏&&|&&7
你可能感兴趣的文章
你可能感兴趣的文章
分享到微博?
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。在互联网上可以免费使用的在线地图有很多种,包括google map,百度地图,高德地图,腾讯地图,天地图等等。各种地图并没有使用同样的坐标系,这样就导致更换地图API时,使用同样的经纬度在不同的地图底图上,会存在偏差,这种变差还比较大。在GPS定位技术以及在线地图普遍使用的今天,即使是极细微的偏差,也会造成使用上的极大不便。
下面将提供各类地图经纬度的转换方法,用JavaScript语言实现。
//转换常数
var x_pi = 3.79324 * 3000.0 / 180.0;
var pi = 3.79324;
var ee = 0.;
function transformLon(x, y) {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;
function transformLat(x, y) {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;
function outOfChina(lat, lon) {
if (lon & 72.004 || lon & 137.8347)
if (lat & 0.8293 || lat & 55.8271)
* WGS-84:是国际标准,GPS坐标(Google Earth使用、或者GPS模块、天地图)
* GCJ-02:中国坐标偏移标准,Google Map、高德、腾讯使用
* BD-09:百度坐标偏移标准,Baidu Map使用
* wgLat 纬度
* wgLon 经度
* WGS-84 到 GCJ-02 的转换(即 GPS 加偏)
function wgs_gcj_encrypts(wgLat, wgLon) {
var point={};
if (outOfChina(wgLat, wgLon)) {
point.lat=wgL
point.lng=wgL
var dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
var dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
var radLat = wgLat / 180.0 *
var magic = Math.sin(radLat);
magic = 1 - ee * magic *
var sqrtMagic = Math.sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);
var lat = wgLat + dL
var lon = wgLon + dL
point.lat=
point.lon=
* wgLat 纬度
* wgLon 经度
* BD-09转换GCJ-02
* 百度转google
function bd_google_encrypt(bd_lat, bd_lon){
var point={};
var x = bd_lon - 0.0065;
var y = bd_lat - 0.006;
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
var theta =Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
var gg_lon = z * Math.cos(theta);
var gg_lat = z * Math.sin(theta);
point.lat=gg_
point.lon=gg_
* gg_lat 纬度
* gg_lon 经度
* GCJ-02转换BD-09
* Google地图经纬度转百度地图经纬度
function google_bd_encrypt(gg_lat, gg_lon){
var point={};
var x = gg_
var y = gg_
var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
var bd_lon = z * Math.cos(theta) + 0.0065;
var bd_lat = z * Math.sin(theta) + 0.006;
point.lat=bd_
point.lon=bd_
阅读(...) 评论()}

我要回帖

更多关于 经纬度转换器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信