mapathon 2013 - google maps javascript api

40
Ritesh Ambastha, iWillStudy.com, 9 th March 2013

Upload: iwillstudycom

Post on 08-May-2015

1.000 views

Category:

Education


2 download

DESCRIPTION

Session 1 PPT of Mapathon organized by Google Developers Group, Ahmedabad

TRANSCRIPT

Page 1: Mapathon 2013 - Google Maps Javascript API

Ritesh Ambastha, iWillStudy.com, 9th March 2013

Page 2: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Google Maps API

JavaScript API v3

Maps API Web

Services

Google Places API

Static Maps API

Street View Image API

Earth API

Google Maps SDK for iOS

Maps Android API

Deprecated API

JavaScript API v3

Page 3: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Google Maps JavaScript API v3

Concepts Events Controls

Styles Overlays Layers

Map Types

Services Libraries

Page 4: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Getting Started

API Key APIs ConsoleHelloWorld Program

Page 5: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Obtain API Key

https://code.google.com/apis/console

Page 6: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Create Client ID

Page 7: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Client ID Settings

Page 8: Mapathon 2013 - Google Maps Javascript API

Let’s write the very first HTML

HelloWorld !!

Page 9: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Basic Terminology

•API Key•SensorScript

•<!DOCTYPE HTML>HTML5• var mapOptions = {

  center: new google.maps.LatLng(22,72),  zoom: 8,  mapTypeId: google.maps.MapTypeId.ROADMAP};

Map Options

Page 10: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Basic Terminology

•ROADMAP•SATELLITE •HYBRID•TERRAIN

Map Types

• var map = new google.maps.Map(document.getElementById("map_canvas"),    mapOptions);

Map Object

• <body onload="initialize()">Load Map

Page 11: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

HelloWorld Program

<script type="text/javascript"      src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&sensor=SET_TO_TRUE_OR_FALSE"></script>

<script type="text/javascript">      function initialize() {        var mapOptions = {          center: new google.maps.LatLng(22.1,77.2),          zoom: 8,          mapTypeId: google.maps.MapTypeId.ROADMAP        };        var map = new google.maps.Map(document.getElementById("map_canvas"),            mapOptions);      }</script>

Page 12: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

6<!DOCTYPE html><html> <head> <script type="text/javascript” src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDVBGLEP0GQpiuDGvNBAaclm62Z0ujZz7U&sensor=false"> </script> <script type="text/javascript"> function initialize() { var mapOptions = { center: new google.maps.LatLng(22.9909363,72.48775950000004), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); } </script> </head>

<body onload="initialize()"> <div id="map_canvas" style="width:500px; height:500px"></div> </body></html>

Page 13: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Output

Page 14: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Purchase Google Maps API, ifYour site is only

available to paying

customers.

Your site is only accessible within your company or on your intranet.

Your application relates to enterprise dispatch,

fleet management, business asset tracking, or similar applications.

Page 15: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Usage Limits & Billing

ServiceUsage limit

(per day)

1,000 excess map loads

(in U.S. dollars)

JS Maps API v3 25,000 $0.50

JS Maps API v2 (Deprecated)

25,000 $1.00

Static Maps API 25,000 $0.50

Street View Image API

25,000 $0.50

Page 16: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Google Maps Events

User Events•google.maps.marker object can listen to the following user events•'click'•'dblclick'•'mouseup'•'mousedown'•'mouseover'•'mouseout'

MVC State Change

•Whenever an object's property changes, the API will fire an event that the property has changed. •For example, the API will fire a event on a map when the map's zoom level changes. You can intercept these state changes by registering  event handlers on the namespace method

For example, the API will fire azoom_changed event on a map when the map's zoom level changes. You can intercept these state changes by registering addListener() event handlers on the eventnamespace metho

Page 17: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Google Maps Events

User Events

•google.maps.marker object can listen to the following user events•'click'•'dblclick'•'mouseup'•'mousedown'•'mouseover'•'mouseout'

For example, the API will fire azoom_changed event on a map when the map's zoom level changes. You can intercept these state changes by registering addListener() event handlers on the eventnamespace metho

Events also typically pass

arguments within the event noting

some UI state (such as the

mouse position).

Page 18: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Google Maps Events

MVC State Change

•MVC events do not pass arguments within their event. •You will want to inspect the property that changed on an MVC state change by calling the appropriate Property method on that object.

For example, the API will fire azoom_changed event on a map when the map's zoom level changes. You can intercept these state changes by registering addListener() event handlers on the eventnamespace metho

Page 19: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform an example

pan-back-to-marker.html

Page 20: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Arguments in UI EventsUI events within the Google Maps API V3 typically pass an event argument, which can be accessed by the event listenerFor example, a UI  event typically passes a  containing a  property denoting the clicked location on the mapLets perform an example which adds an event listener for the map, and creates a marker when the user clicks on the map at the clicked location.

event-arguments.html

Page 21: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Map Controls

Zoom Pan Scale

MapType

Street View Rotate

Overview Map

Page 22: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Adding Controls to the Map{

  panControl: boolean,

  zoomControl: boolean,

  mapTypeControl: boolean,

  scaleControl: boolean,

  streetViewControl: boolean,

  overviewMapControl:

boolean}

function initialize() {  var mapOptions = {

    zoom: 4,    center: new

google.maps.LatLng(-33, 151),

    panControl: false,    zoomControl: false,    scaleControl: true,

    mapTypeId: google.maps.MapTypeId.ROA

DMAP  }

  var map = new google.maps.Map(document.getElementById("map_canva

s"),        mapOptions);

}

Page 23: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform an example

map-controls.html

Page 24: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Maps – Styles and Syntax

Map Features

•Geographic elements that can be targeted on the map. These include roads, parks, bodies of water, and more, as well as their labels.

Stylers•Color and visibility properties that can be applied to map features. They define the display color through a combination of hue, color, and lightness/gamma values.

Page 25: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Map FeaturesThe following element types are supported:

•all (default) selects all elements of that feature.•geometry selects all geometric elements of that feature.

• geometry.fill selects only the fill of the feature's geometry.

• geometry.stroke selects only the stroke of the feature's geometry.

•labels selects only textual labels associated with that feature.

• labels.icon selects only the icon displayed within the feature's label.

• labels.text selects only the text of the label.• labels.text.fill selects only the fill of the label. The fill of a

label is typically rendered as a colored outline that surrounds the label text.

• labels.text.stroke selects only the stroke of the label's text.

Page 26: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Map Features – Code Snippet

The following specification selects the labels for all local roads:

{  featureType: "road.local",  elementType: "labels"}

Page 27: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Map Stylers

hue lightness

Saturation

gamma innverse_lightness visibility

color weight

Page 28: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Stylers – Code Snippet

The following specification selects the labels for all local roads:

stylers: [  { hue: "#00d4ff" },  { saturation: 60 },  { lightness: -20 },  { gamma: 1.51 }]

Page 29: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform two examples

style-example.htmlstyle-example2.html

Page 30: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

The Styled Map Wizard

http://gmaps-samples-v3.googlecode.com/svn/

trunk/styledmaps/wizard/index.html

Page 31: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Overlays

Overlays are objects on the map that are tied to

latitude/longitude coordinates, so they

move when you drag or zoom the map

Page 32: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Overlays – To Learn

Adding Overlays

Removing Overlays Symbols Markers

Simple Icons

Complex Icons

Polylines

Polygons

Circles and Rectangles

User-Editable Shapes

Editing Events

Drawing Library

Info Windows

Ground Overlays

Custom Overlays

Page 33: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform two examples

simple-marker.htmlmarker-

animate.html

Page 34: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform two examples

overlay.htmloverlay-remove.html

Page 35: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform three examples

marker-icon.htmlpolygon.htmlpolyline.html

Page 36: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Layers

KML GeoRSS

Heatmap

Traffic

Layers are objects on the map that consist of one or more separate items, but are manipulated as a

single unit.

Page 37: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

KML & GeoRSS Layers

KML GeoRSS

The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.

Page 38: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s perform two examples

kml-example.htmlgeorss.html

Page 39: Mapathon 2013 - Google Maps Javascript API

Ahmedabad

Let’s code the examples for each

Heatmap

Traffic

Transit Bicycle

Page 40: Mapathon 2013 - Google Maps Javascript API

Ritesh [email protected]/riteshambasthaTwitter.com/riteshambastha+91-9408098777

Keep Mapping