Open API 之 Google Map体验

简介: 上一个介绍了Open API的一些参考资源集 http://www.cnblogs.com/2018/archive/2011/08/27/2155274.html 下面以一个常用的google map这个open api为例说明如何应用 概念基础 目前的版本是3,相对版本2有较大服务的修改。

上一个介绍了Open API的一些参考资源集 http://www.cnblogs.com/2018/archive/2011/08/27/2155274.html

下面以一个常用的google map这个open api为例说明如何应用

概念基础

目前的版本是3,相对版本2有较大服务的修改。

Marker

用于在地图特定位置显示信息的一个图标

A marker is basically a small image that is positioned at a specific place on a map. Its most frequent incarnation is the familiar drop-shaped marker that is the default marker in Google Maps

相关和图标参考资料

http://gmaps-samples.googlecode.com/svn/trunk/markers/

http://code.google.com/p/google-maps-icons

如果一个区域显示太多的图标,查看起来不好区分,此时可以使用如下的工具库分组显示Marker:

MarkerClusterer

http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries

http://google-maps-utility-libraryv3.googlecode.com/svn/tags/markerclusterer/1.0/

MarkerManager

http://google-maps-utility-libraryv3.googlecode.com/svn/tags/markermanager/1.0/

Marker Icon的相关地址

http://www.powerhut.co.uk/googlemaps/custom_markers.php

http://www.cycloloco.com/shadowmaker/shadowmaker.htm

http://www.cartosoft.com/mapicons/

InfoWindow

一般用于显示相关信息的窗口

Geocoding

Geocoding is an integrated part of the Google Maps API. When you send in an address, you get the

coordinates for that address back. It’s that simple! This is very handy in circumstances where you only have an address, but you still somehow want to automatically plot it on a map.

由于这个计算比较消耗资源,目前一个IP地址24小时内只运行2500个请求

API

Google map是基于Javascript提供的一个库应用支持,具体地址在

http://code.google.com/apis/maps/documentation/javascript/reference.html

例子

页面中引入google map API:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

通过API建立地图和相关的处理:

        // Creating a reference to the mapDiv
            var mapDiv = document.getElementById('map');
          
            // Creating a latLng for the center of the map beijing
            var latlng = new google.maps.LatLng(39.904, 116.407);
            var options = {
                    zoom: 10,
                    center: latlng,
                    mapTypeId: google.maps.MapTypeId.ROADMAP,
                    mapTypeControl: true,
                    mapTypeControlOptions: {
                        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
                        mapTypeIds: [
                            google.maps.MapTypeId.ROADMAP,
                            google.maps.MapTypeId.SATELLITE
                        ],
                        position: google.maps.ControlPosition.TOP_RIGHT
                    },
                    disableDefaultUI: false,
                    scrollwheel: true,
                    draggableCursor: 'move',
                    scaleControl: true,
                    disableDoubleClickZoom: true
            };
           
            // Creating the map
            map = new google.maps.Map(mapDiv, options);

效果:

image

以上例子具体地址:

https://skydrive.live.com/?cid=56b433ad3d1871e3&sc=documents&id=56B433AD3D1871E3%21266

下载后直接在浏览器即可查看,主要操作:

1、地图上点击出提示信息

2、点击“取坐标”,可以进行查询,同时显示一个Marker提示,在Marker上双击可以查看明细

可见,不多的代码我们就可以构建一个很丰富的应用。

参考

如何阅读API

方法

如构造函数方法如下:

Map(mapDiv:Node, opts?:MapOptions)

方法名,括号内是参数变量,参数定义如下:

variableName:variableType

冒号前是变量名,后是变量类型,变量名后有?,表示是可选参数

Data Types

类型有:原生类型(如string, number,boolean),自定义类型(如MouseEvent ,StreetviewPanorama)

需要注意的是: Array 和 MVCArrays 有些不同.

Array.<MapTypeId>

表示一个包含MapTypeId对象的数组类型

MVCArrays are a special kind of array, so the notation for them looks the same. Here’s what the overlayMapTypes property of the Map object looks like:

MVCArray.<MapType>

In this case, it means that the value for this property is an MVCArray that contains MapType objects.

The Namespace

All the classes of the Google Maps API reside in the namespace google.maps. That means whatever class or method you want to call always starts with google.maps. Here’s, for example, how to call the constructor for the Marker class:

new google.maps.Marker();

So, whenever you need to use a class or object, make sure to always insert the namespace name in front of it.

图书

Beginning Google Maps API 3 这本书对google API有详细的描述,具体参考

http://www.svennerberg.com/bgma3

http://www.apress.com/9781430228028

相关文章
|
1月前
|
人工智能 Java API
Google Gemini API 接口调用方法
Google 最近发布的 Gemini 1.0 AI 模型通过其升级版,Gemini,标志着公司迄今为止最为强大和多功能的人工智能技术的突破。
|
2月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
21 0
|
2月前
|
传感器 编解码 数据处理
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
22 0
|
2月前
Google Earth Engine(GEE)——从列表中少选所需要的数字不用map函数,还能如何实现?简单方法介绍
Google Earth Engine(GEE)——从列表中少选所需要的数字不用map函数,还能如何实现?简单方法介绍
17 0
|
6月前
|
JSON 负载均衡 前端开发
一文带你详细了解Open API设计规范
一文带你详细了解Open API设计规范
923 0
|
6月前
|
Web App开发 人工智能 Linux
宝塔快速反代openai官方的API接口,实现国内调用open ai
宝塔快速反代openai官方的API接口,实现国内调用open ai
610 0
|
2月前
Google Earth Engine(GEE)——如何建立一个逐日的时序图表chart用map进行遍历
Google Earth Engine(GEE)——如何建立一个逐日的时序图表chart用map进行遍历
18 0
|
2月前
Open Google Earth Engine(OEEL)——oeel.plotly.plot绘制MODIS影像中土地分类的变化情况
Open Google Earth Engine(OEEL)——oeel.plotly.plot绘制MODIS影像中土地分类的变化情况
26 0
|
2月前
|
JSON 搜索推荐 API
【2024更新】如何使用google index api来自动提交url
本文提供了一个详细的指南,说明如何创建并使用使用google index api,google自动提交url来优化seo。
38 0
|
6月前
|
关系型数据库 MySQL API
Go语言微服务框架 - 6.用Google风格的API接口打通MySQL操作
随着RPC与MySQL的打通,整个框架已经开始打通了数据的出入口。 接下来,我们就尝试着实现通过RPC请求操作MySQL数据库,打通整个链路,真正地让这个平台实现可用。
18 0