Baidu與Google地圖API初探

前天週六,有個好友過來玩,他說想在他的網站中加入地圖導航模塊,但不知道選擇哪個第三方Map API

在網上查了下BaiduGoogleQQ和MapBar等4種Map API(都是採用JS開放API),也查看了它們的SDK開發文檔,下面來談談自己的體會

Map API文檔

BMap API(Baidu)與google.maps API(Google)文檔相對最完備、詳盡、簡潔,並且給出了很多學習用例,非常適合初學者入門學習、應用開發

QMap API(QQ)與MapBar API(MapBar)文檔雖然也比較完備,但示例與代碼分開了,不能很好體現代碼與效果的所見即所得

Map Function

BMap API和Google.maps API,應該就可以滿足絕大部分需求

就易用性和色彩柔和性,推薦Baidu BMap API

就精確性和世界地圖,推薦Google Google.maps API

精確性:

Baidu BMap提供小數點後六位的精度,如(116.397128, 39.916527);

Google google.maps則提供小數點後14位的精度,如New York(40.69847032728747, -73.9514422416687)

世界性:

Baidu BMap僅提供中國區域(包括港、澳,但目前不包含臺灣、日本,可能百度日本分公司含有);

Google google.maps則提供全球區域的地圖(支持本地化

3D效果:

Baidu BMap目前僅提供幾個中國大城市3D地圖(如北、上、廣和深圳);

Google google.maps則支持大部分國家的3D車載導航(目前僅支持中國部分城市,如上海)

API風格:

BMap API和google.maps的API接口是有些區別,兩者的API風格,可以代表其它幾款開放的Map API風格

QMap API與google.maps API接口的風格很類似,MapBar API則與BMap API接口風格很類似,甚至有些函數接口名都相同,如centerAndZoom

下面,簡單做一下對比 BMap API(Baidu)和google.maps API(Google)——都是以“天安門”爲參照原點

BMap API(Baidu)

<!doctype html>

<html>
<head>
    
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
    
<title>Baidu Map V1.2</title>
    
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&services=true">
        
<!-- add baidu map api -->
    
</script>
</head>
<body>
    
<div id="container" style="width: 600px; height: 400px;">
    
</div>
</body>
</html>
<script type="text/javascript">
    
var map = new BMap.Map("container");                    // new Map
    var point = new BMap.Point(116.39712839.916527);        // Location, (經度, 緯度)
    map.centerAndZoom(point, 15);                           // show Map

    
// 添加縮放功能
    map.enableScrollWheelZoom();
    map.enableKeyboard();
</script>

 效果圖如下:

google.maps API(Google)
<!doctype html>

<html>
<head>
    
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    
<meta http-equiv="content-type" content="text/html; charset=gbk" />
    
<title>Google Map V3</title>
    
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"
        rel
="stylesheet" type="text/css" />
    
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
    
<!-- add google map api -->
    
</script>
</head>
<body onload="initialize()">
    
<div id="container" style="width: 600px; height: 400px;">
    
</div>
</body>
</html>
<script type="text/javascript">
    
function initialize() 
    {
        
var myLatlng = new google.maps.LatLng(39.916527116.397128);     // location, (緯度, 經度)
        var myOptions = 
        {
            zoom: 
12,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        
var obj = document.getElementById("container");             // container
        var map = new google.maps.Map(obj, myOptions);                 // show map
    }
</script>
效果圖如下:
url:
http://greatverve.cnblogs.com/archive/2011/07/12/google-baidu-map-api.html

總體感覺,四種Map API各有千秋,BMap API(Baidu)和google.maps(Google)代表了兩個Map API主流,可以滿足絕大部分用戶需求;

QMap API和MapBar API都是後起之秀,專注技術的同時,也可以優化、增加一些API文檔,畢竟開放API就是爲了讓更多的人去使用嘛

IT技術需要競爭,因爲競爭,所以創新;因爲創新,所以進步;因爲進步,所以開放,祝願中國IT領域不斷創新、進步、開放、發展

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章