js如何将高德导航官网免费版地图坐标转换成百度地图坐标

博客分类:
本文主要讲解如何通过百度地图API根据某个经纬度值(地理坐标)查询对应的地址信息以及该地址周边的POI(Point of Interest,兴趣点)信息。
百度地图移动版API不仅包含构建地图的基本接口,还集成了众多搜索服务,包括:位置检索、周边检索、范围检索、公交检索、驾乘检索、步行检索、地址信息查询等。
百度地图移动版API提供的搜索服务主要是通过初始化MKSearch类,注册搜索结果的监听对象MKSearchListener来实现异步搜索服务。首先需要自定义一个MySearchListener类,它实现MKSearchListener接口,然后通过实现接口中不同的回调方法,来获得对应的搜索结果。MySearchListener类的定义如下:
public class MySearchListener implements MKSearchListener {
public void onGetAddrResult(MKAddrInfo result, int iError) {
public void onGetDrivingRouteResult(MKDrivingRouteResult result, int iError) {
public void onGetPoiResult(MKPoiResult result, int type, int iError) {
public void onGetTransitRouteResult(MKTransitRouteResult result, int iError) {
public void onGetWalkingRouteResult(MKWalkingRouteResult result, int iError) {
说明:上面的类定义只是在说明MKSearchListener类的5个方法的作用,全都是空实现,并未给出具体的实现。根据你要检索的内容,再去具体实现上面对应的方法,就能获取到搜索结果。例如:1)你想通过一个地理坐标(经纬度值)来搜索地址信息,那么只需要具体实现上面的onGetAddrResult()方法就能得到搜索结果;2)如果你想搜索驾车路线信息,只需要具体实现onGetDrivingRouteResult()方法就能得到搜索结果。
紧接着,需要初始化MKSearch类:
mMKSearch = new MKSearch();
mMKSearch.init(mapManager, new MySearchListener());
经过上面两步之后,就可以通过调用MKSearch所提供的一些检索方法来搜索你想要的信息了。
下面给出一个具体的示例:根据某个经纬度值(地理坐标)查询对应的地址信息以及该地址周边的POI(Point of Interest,兴趣点)信息。1)布局文件res/layout/query_address.xml
version="1.0" encoding="utf-8"
xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="经度:"
android:id="@+id/longitude_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="106.720397"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="纬度:"
android:id="@+id/latitude_input"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="26.597239"
android:id="@+id/query_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="地址查询"
android:id="@+id/address_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
虽然定义了MapView,但是设置了android:visibility="gone"将其隐藏
因为本示例并不需要显示地图,但不定义又不行(baidu map api的要求)
android:id="@+id/map_View"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:visibility="gone"
2)继承com.baidu.mapapi.MapActivity的Activity类
package com.liufeng.
import android.os.B
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.EditT
import android.widget.TextV
import com.baidu.mapapi.BMapM
import com.baidu.mapapi.GeoP
import com.baidu.mapapi.MKAddrI
import com.baidu.mapapi.MKDrivingRouteR
import com.baidu.mapapi.MKPoiI
import com.baidu.mapapi.MKPoiR
import com.baidu.mapapi.MKS
import com.baidu.mapapi.MKSearchL
import com.baidu.mapapi.MKTransitRouteR
import com.baidu.mapapi.MKWalkingRouteR
import com.baidu.mapapi.MapA
public class QueryAddressActivity extends MapActivity {
private BMapManager mapM
private MKSearch mMKS
private EditText longitudeEditT
private EditText latitudeEditT
private TextView addressTextV
private Button queryB
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.query_address);
mapManager = new BMapManager(getApplication());
mapManager.init("285B415EBAB2A50ADA7F03C777C4", null);
super.initMapActivity(mapManager);
mMKSearch = new MKSearch();
mMKSearch.init(mapManager, new MySearchListener());
longitudeEditText = (EditText) findViewById(R.id.longitude_input);
latitudeEditText = (EditText) findViewById(R.id.latitude_input);
addressTextView = (TextView) findViewById(R.id.address_text);
queryButton = (Button) findViewById(R.id.query_button);
queryButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String longitudeStr = longitudeEditText.getText().toString();
String latitudeStr = latitudeEditText.getText().toString();
int longitude = (int) (1000000 * Double.parseDouble(longitudeStr));
int latitude = (int) (1000000 * Double.parseDouble(latitudeStr));
mMKSearch.reverseGeocode(new GeoPoint(latitude, longitude));
} catch (Exception e) {
addressTextView.setText("查询出错,请检查您输入的经纬度值!");
protected boolean isRouteDisplayed() {
return false;
protected void onDestroy() {
if (mapManager != null) {
mapManager.destroy();
mapManager = null;
super.onDestroy();
protected void onPause() {
if (mapManager != null) {
mapManager.stop();
super.onPause();
protected void onResume() {
if (mapManager != null) {
mapManager.start();
super.onResume();
public class MySearchListener implements MKSearchListener {
public void onGetAddrResult(MKAddrInfo result, int iError) {
if (result == null) {
StringBuffer sb = new StringBuffer();
sb.append(result.strAddr).append("/n");
if (null != result.poiList) {
for (MKPoiInfo poiInfo : result.poiList) {
sb.append("----------------------------------------").append("/n");
sb.append("名称:").append(poiInfo.name).append("/n");
sb.append("地址:").append(poiInfo.address).append("/n");
sb.append("经度:").append(poiInfo.pt.getLongitudeE6() / 1000000.0f).append("/n");
sb.append("纬度:").append(poiInfo.pt.getLatitudeE6() / 1000000.0f).append("/n");
sb.append("电话:").append(poiInfo.phoneNum).append("/n");
sb.append("邮编:").append(poiInfo.postCode).append("/n");
sb.append("类型:").append(poiInfo.ePoiType).append("/n");
addressTextView.setText(sb.toString());
public void onGetDrivingRouteResult(MKDrivingRouteResult result, int iError) {
public void onGetPoiResult(MKPoiResult result, int type, int iError) {
public void onGetTransitRouteResult(MKTransitRouteResult result, int iError) {
public void onGetWalkingRouteResult(MKWalkingRouteResult result, int iError) {
3)AndroidManifest.xml中的配置
version="1.0" encoding="utf-8"
xmlns:android="/apk/res/android"
package="com.liufeng.baidumap"
android:versionCode="1"
android:versionName="1.0"
android:icon="@drawable/icon" android:label="@string/app_name"
android:name=".QueryAddressActivity" android:label="@string/app_name"
android:name="android.intent.action.MAIN"
android:name="android.intent.category.LAUNCHER"
android:minSdkVersion="4"
android:name="android.permission.INTERNET"
android:name="android.permission.ACCESS_FINE_LOCATION"
android:name="android.permission.ACCESS_NETWORK_STATE"
android:name="android.permission.ACCESS_WIFI_STATE"
android:name="android.permission.CHANGE_WIFI_STATE"
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:name="android.permission.READ_PHONE_STATE"
4)运行结果截图及说明
程序在模拟器上运行的初始效果如上图所示。可以看出,地图并没有显示出来,这和我们在设计时布局时所设想的一样;另外两个输入框中也分别显示了默认给出的经纬度值。
点击“地址查询”按钮后,将看到如下图所示包含了查询结果的界面:
说明:图上的“贵州省贵阳市云岩区普陀路”正是我们要查询的地理坐标(经度:106.720397,纬度:26.597239)所对应的地址信息;同时该地址信息下方还显示出了该地址附近的10个兴趣点(POI),每个兴趣点分别包含了“名称”、“地址”、“经纬度”、“电话”、“邮编”和“兴趣点类型”信息。
备注:如果本文的示例继续做下去,就应该将MapView显示出来,同时结合第8篇文章“”所介绍的内容将地址信息和兴趣点标注在地图上。我想这两方面的内容都已做过详细讲解并给出了示例,再来实现这个应该并不是什么难事,看文章的你就动动手来完成它吧!
浏览 16659
浏览: 376936 次
来自: 北京
明显就有要求的嘛
很不错,就是需要这个方法
label = [[UILabel a ...
/iphone- ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'如何将高德地图坐标转换成百度地图坐标????急急急!!!_百度地图api吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:5,783贴子:
如何将高德地图坐标转换成百度地图坐标????急急急!!!收藏
如何将高德地图上获取到的坐标转换成百度地图坐标?做好有Demo能参考、、、谢啦
2017上海佘山汇丰高尔夫冠军赛10月底开赛了
这位朋友,百度地图api不是有么// 将google地图、soso地图、aliyun地图、mapabc地图和amap地图// 所用坐标转换成百度坐标
CoordinateConverter converter
= new CoordinateConverter();
converter.MON);
// sourceLatLng待转换坐标
converter.coord(sourceLatLng);
LatLng desLatLng = converter.convert();
登录百度帐号推荐应用js使用百度地图定位获取经纬度
作者:用户
本文讲的是js使用百度地图定位获取经纬度,
最近的项目中需要使用定位功能,并且获取当前位置的经纬度,查阅资料了整理了如下代码:
function locationPosition(){
var geolocation = new BMap.Geolocation();
最近的项目中需要使用定位功能,并且获取当前位置的经纬度,查阅资料了整理了如下代码:
function locationPosition(){
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(r){
var city_lat = r.
var city_lng = r.
Cookies.set("save_city_latitude",city_lat);
Cookies.set("save_city_longitude",city_lng);
// console.log(city_lat);
// console.log(city_lng);
if(this.getStatus() == BMAP_STATUS_SUCCESS){
var geoc = new BMap.Geocoder();
var pt = r.
geoc.getLocation(pt, function(rs){
// 获取经纬度
var addComp = rs.addressC
// alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
$city =$(".head-left & a & span");
// var city_name = $.fn.cookie('location_city');
var city_name = Cookies.get('location_city');
//console.log(addComp.city);
if (city_name == addComp.city){
// TODO 定位城市和cookie值一致, 则不操作
$city.text(addComp.city);
$(".city-now").text(addComp.city);
$city.text(city_name);
if (confirm('当前位置和定位城市不一致, 是否更改成当前位置?')) {
$city.text(addComp.city);
$(".city-now").text(addComp.city);
// $.fn.cookie('location_city', addComp.city);
// Cookies.set('location_city', addComp.city);
// setLocation();
var city = Cookies.set('location_city',addComp.city);
currount_city_name = addComp.
getData(1,city_lat,city_lng,currount_city_name);
getArea(currount_city_name);
alert('定位失败');
},{enableHighAccuracy: true});
locationPosition();
var city_lat = r.
var city_lng = r.
可以获得当前经纬度。
以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索获取手机定位经纬度js、js百度地图经纬度定位、js高德地图获取经纬度、js百度地图获取经纬度、js点击地图获取经纬度,以便于您获取更多的相关知识。
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
6款热门基础云产品6个月免费体验;2款产品1年体验;1款产品2年体验
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
开发者常用软件,超百款实用软件一站式提供
云栖社区()为您免费提供相关信息,包括
获取手机定位经纬度js、js百度地图经纬度定位、js高德地图获取经纬度、js百度地图获取经纬度、js点击地图获取经纬度的信息
,所有相关内容均不代表云栖社区的意见!iOS-地理坐标转换,原生地图获取的原始坐标转换为地图真实坐标
GPS以及iOS定位获得的坐标是地理坐标系WGS1984,Web地图一般用的坐标细是投影坐标系WGS 1984 Web Mercator,国内出于相关法律法规要求,对国内所有GPS设备及地图数据都进行了偏移处理,代号GCJ-02,这样GPS定位获得的坐标与地图上的位置刚好对应上,特殊的是百度地图在这基础上又进行一次偏移,所以在处理系统定位坐标及相关地图SDK坐标时需要转换处理下,根据网络资源,目前有一些公开的转换算法。
系统定位坐标显示在原生地图、谷歌地图或高德地图&WGS1984转GCJ-02
苹果地图及谷歌地图用的都是高德地图的数据,所以这三种情况坐标处理方法一样,即将WGS1984坐标转换成偏移后的GCJ-02才可以在地图上正确显示位置。
通过这个工具类可将iOS原生地图获取的坐标点转换为地图上正确表示的真实坐标点:
GPSLocationTool.h
Created by carayfire-Develop on 16/6/8.
Copyright ? 2016年 Crazyfire technology development Co. Ltd. All rights reserved.
@interface GPSLocationTool : NSObject
public:原生地图获取坐标转化为真实坐标
@param latLng 原生坐标点
@return 真实坐标点
+ (CLLocationCoordinate2D)transform:(CLLocationCoordinate2D)latL
GPSLocationTool.m
Created by carayfire-Develop on 16/6/8.
Copyright ? 2016年 Crazyfire technology development Co. Ltd. All rights reserved.
#import &GPSLocationTool.h&
@implementation GPSLocationTool
const double a = ;
const double ee = 0.;
public:原生地图获取坐标转化为真实坐标
@param latLng 原生坐标点
@return 真实坐标点
+ (CLLocationCoordinate2D)transform:(CLLocationCoordinate2D) latLng
double wgLat = latLng.
double wgLon = latLng.
double mgL
double mgL
if ([self outOfChina:wgLat :wgLon ])
return latL
double dLat = [self transformLat:wgLon-105.0 :wgLat - 35 ];
double dLon = [self transformLon:wgLon-105.0 :wgLat - 35 ];
double radLat = wgLat / 180.0 * M_PI;
double magic = sin(radLat);
magic = 1 - ee * 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);
mgLat = wgLat + dL
mgLon = wgLon + dL
CLLocationCoordinate2D loc2D ;
loc2D.latitude = mgL
loc2D.longitude = mgL
return loc2D;
#pragma mark private
+ (BOOL) outOfChina:(double) lat :(double) lon
if (lon & 72.004 || lon & 137.8347) {
if (lat & 0.8293 || lat & 55.8271) {
+ (double) transformLat:(double)x
:(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 /
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 /
+ (double) transformLon:(double) x :(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 /
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 /}

我要回帖

更多关于 高德地图gps坐标转换 的文章

更多推荐

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

点击添加站长微信