Google Maps API - DevFest Karlsruhe

87
Martin Kleppe / Ubilabs Google Maps API

description

The Google Maps API lets you embed Google Maps in your own web pages in just a few simple steps. Since the launch in 2005 Google is adding tons of features to the API and constantly pushes the limits with the use of modern browsers. It is one of the most used JavaScript libraries and implemented by more than 350,000 websites. This talk gives you an overview of the latest API additions – such as the Canvas layer, the Places API and real time traffic conditions – and showcase stunning web applications build on top of these libraries. Martin shares his experience on how to programmatically and visually handle large amounts of custom data.

Transcript of Google Maps API - DevFest Karlsruhe

Page 1: Google Maps API - DevFest Karlsruhe

Martin Kleppe / Ubilabs

Google Maps API

Page 2: Google Maps API - DevFest Karlsruhe

@aemkeiMartin Kleppe |

Page 3: Google Maps API - DevFest Karlsruhe
Page 4: Google Maps API - DevFest Karlsruhe
Page 5: Google Maps API - DevFest Karlsruhe
Page 6: Google Maps API - DevFest Karlsruhe
Page 7: Google Maps API - DevFest Karlsruhe
Page 8: Google Maps API - DevFest Karlsruhe
Page 9: Google Maps API - DevFest Karlsruhe

Maps API

Page 10: Google Maps API - DevFest Karlsruhe

> 150 Features> 150 Features

Page 11: Google Maps API - DevFest Karlsruhe

Map MapTypeId Controls MapTypeControlStyle ScaleControlStyle ZoomControlStyle ControlPosition Overlays Marker MarkerImage MarkerShape Symbol SymbolPath Animation InfoWindow Polyline IconSequence Polygon PolyMouseEvent Rectangle Circle GroundOverlay OverlayView MapPanes MapCanvasProjection Services Geocoder GeocoderRequest GeocoderStatus GeocoderResult GeocoderAddressComponent GeocoderGeometry GeocoderLocationType DirectionsRenderer DirectionsService DirectionsRequest TravelMode UnitSystem DirectionsWaypoint DirectionsStatus DirectionsResult DirectionsRoute DirectionsLeg DirectionsStep Distance Duration Time TransitDetails TransitStop TransitLine TransitAgency TransitVehicle ElevationService LocationElevationRequest PathElevationRequest ElevationResult ElevationStatus MaxZoomService MaxZoomResult MaxZoomStatus DistanceMatrixService DistanceMatrixRequest DistanceMatrixResponse DistanceMatrixResponseRow DistanceMatrixResponseElement DistanceMatrixStatus DistanceMatrixElementStatus Map TypesMapType MapTypeRegistry Projection ImageMapType StyledMapType MapTypeStyle MapTypeStyleFeatureType MapTypeStyleElementType MapTypeStyler Layers BicyclingLayer FusionTablesLayer FusionTablesQuery FusionTablesStyle FusionTablesHeatmap FusionTablesMouseEvent FusionTablesCell KmlLayer KmlLayerMetadata KmlLayerStatus KmlMouseEvent KmlFeatureData KmlAuthor TrafficLayer TransitLayer StreetView StreetViewPanorama StreetViewLink StreetViewPov StreetViewPanoramaData StreetViewLocation StreetViewTileData StreetViewService StreetViewStatus Events MapsEventListener event MouseEvent Base LatLng LatLngBounds Point Size MVCObject MVCArray Geometry Library encoding spherical poly AdSense Library AdUnit AdFormat Panoramio Library PanoramioLayer PanoramioFeature PanoramioMouseEvent Places Library Autocomplete ComponentRestrictions PlaceDetailsRequest PlaceGeometry PlaceResult PlaceSearchRequest PlaceSearchPagination PlacesServicePlacesServiceStatus RankBy TextSearchRequest Drawing Library DrawingManager OverlayCompleteEvent OverlayType Weather Library CloudLayer WeatherLayer TemperatureUnit WindSpeedUnit LabelColor WeatherMouseEvent WeatherFeature WeatherConditions WeatherForecast Visualization Library HeatmapLayer WeightedLocation

Page 12: Google Maps API - DevFest Karlsruhe

Map MapTypeId Controls MapTypeControlStyle ScaleControlStyle ZoomControlStyle ControlPosition Overlays Marker MarkerImage MarkerShape Symbol SymbolPath Animation InfoWindow Polyline IconSequence Polygon PolyMouseEvent Rectangle Circle GroundOverlay OverlayView MapPanes MapCanvasProjection Services Geocoder GeocoderRequest GeocoderStatus GeocoderResult GeocoderAddressComponent GeocoderGeometry GeocoderLocationType DirectionsRenderer DirectionsService DirectionsRequest TravelMode UnitSystem DirectionsWaypoint DirectionsStatus DirectionsResult DirectionsRoute DirectionsLeg DirectionsStep Distance Duration Time TransitDetails TransitStop TransitLine TransitAgency TransitVehicle ElevationService LocationElevationRequest PathElevationRequest ElevationResult ElevationStatus MaxZoomService MaxZoomResult MaxZoomStatus DistanceMatrixService DistanceMatrixRequest DistanceMatrixResponse DistanceMatrixResponseRow DistanceMatrixResponseElement DistanceMatrixStatus DistanceMatrixElementStatus Map TypesMapType MapTypeRegistry Projection ImageMapType StyledMapType MapTypeStyle MapTypeStyleFeatureType MapTypeStyleElementType MapTypeStyler Layers BicyclingLayer FusionTablesLayer FusionTablesQuery FusionTablesStyle FusionTablesHeatmap FusionTablesMouseEvent FusionTablesCell KmlLayer KmlLayerMetadata KmlLayerStatus KmlMouseEvent KmlFeatureData KmlAuthor TrafficLayer TransitLayer StreetView StreetViewPanorama StreetViewLink StreetViewPov StreetViewPanoramaData StreetViewLocation StreetViewTileData StreetViewService StreetViewStatus Events MapsEventListener event MouseEvent Base LatLng LatLngBounds Point Size MVCObject MVCArray Geometry Library encoding spherical poly AdSense Library AdUnit AdFormat Panoramio Library PanoramioLayer PanoramioFeature PanoramioMouseEvent Places Library Autocomplete ComponentRestrictions PlaceDetailsRequest PlaceGeometry PlaceResult PlaceSearchRequest PlaceSearchPagination PlacesServicePlacesServiceStatus RankBy TextSearchRequest Drawing Library DrawingManager OverlayCompleteEvent OverlayType Weather Library CloudLayer WeatherLayer TemperatureUnit WindSpeedUnit LabelColor WeatherMouseEvent WeatherFeature WeatherConditions WeatherForecast Visualization Library HeatmapLayer WeightedLocation

Page 13: Google Maps API - DevFest Karlsruhe

Location

Page 14: Google Maps API - DevFest Karlsruhe
Page 15: Google Maps API - DevFest Karlsruhe

var location = new google.maps.LatLng( 49.026564, 8.385753);

var options = { zoom: 12, center: location, mapTypeId: google.maps.MapTypeId.ROADMAP};

var map = new google.maps.Map( document.getElementById('map_canvas'), options);

Page 16: Google Maps API - DevFest Karlsruhe

var geocoder = new google.maps.Geocoder();

geocoder.geocode(options, function(results, status) { map.setCenter( results[0].geometry.location );});

var options = { address: "Erzbergerstraße 121, Karlsruhe" };

Page 17: Google Maps API - DevFest Karlsruhe

navigator.geolocation.getCurrentPosition(success, error);

function success(position) { var location = new google.maps.LatLng( position.coords.latitude, position.coords.longitude );

map.setCenter(location);}

function error() { ... }

Page 18: Google Maps API - DevFest Karlsruhe

var input = document.getElementById('input');var autocomplete = new google.maps.places.Autocomplete(input);

autocomplete.bindTo('bounds', map);

google.maps.event.addListener( autocomplete, 'place_changed', function() { var place = autocomplete.getPlace(); ... });

Page 19: Google Maps API - DevFest Karlsruhe
Page 20: Google Maps API - DevFest Karlsruhe

Custom Icons

Page 21: Google Maps API - DevFest Karlsruhe
Page 22: Google Maps API - DevFest Karlsruhe

var image = new google.maps.MarkerImage( 'image.png', new google.maps.Size(20, 20), new google.maps.Point(0, 0), new google.maps.Point(10, 20));

var shadow = ...;

var shape = { coord: [5,5, 5,15, 15,15, 15,5], type: 'poly'};

var marker = new google.maps.Marker({ ... icon: image, shadow: shadow, shape: shape});

Page 23: Google Maps API - DevFest Karlsruhe

Directions

Page 24: Google Maps API - DevFest Karlsruhe

var service = new google.maps.DirectionsService();

var request = { origin: from, destination: to, travelMode: google.maps.TravelMode.DRIVING};

service.route(request, function(response, status) { ...});

Page 25: Google Maps API - DevFest Karlsruhe
Page 26: Google Maps API - DevFest Karlsruhe
Page 27: Google Maps API - DevFest Karlsruhe
Page 28: Google Maps API - DevFest Karlsruhe

"duration" : { "text" : "35 mins", "value" : 2093},

"duration_in_traffic" : { "text" : "46 mins", "value" : 2767}

Page 29: Google Maps API - DevFest Karlsruhe

Elevation

Page 30: Google Maps API - DevFest Karlsruhe
Page 31: Google Maps API - DevFest Karlsruhe
Page 32: Google Maps API - DevFest Karlsruhe

var service = new google.maps.ElevationService();

var options = { path: latLngs, samples: 256};

service.getElevationAlongPath( options, plotElevation);

function plotElevation(results) { ...});

Page 33: Google Maps API - DevFest Karlsruhe

Time Zones

Page 34: Google Maps API - DevFest Karlsruhe
Page 36: Google Maps API - DevFest Karlsruhe

{ dstOffset: 0, rawOffset: 3600, status: "OK", timeZoneId: "Europe/Berlin", timeZoneName: "Central European Standard Time"}

Page 37: Google Maps API - DevFest Karlsruhe

StreetView

Page 38: Google Maps API - DevFest Karlsruhe
Page 39: Google Maps API - DevFest Karlsruhe

var options = { position: location, pov: { heading: 165, pitch: 0, zoom: 1 }};

new google.maps.StreetViewPanorama( document.getElementById('pano'), options);

Page 40: Google Maps API - DevFest Karlsruhe

45°

Page 41: Google Maps API - DevFest Karlsruhe
Page 42: Google Maps API - DevFest Karlsruhe
Page 43: Google Maps API - DevFest Karlsruhe

map.setTilt(45);map.setHeading(90);

Page 44: Google Maps API - DevFest Karlsruhe

Places

Page 45: Google Maps API - DevFest Karlsruhe
Page 47: Google Maps API - DevFest Karlsruhe

var input = document.getElementById('input');var searchBox = new google.maps.places.SearchBox(input);

google.maps.event.addListener( searchBox, 'places_changed', function() { var places = searchBox.getPlaces(); ... });

Page 48: Google Maps API - DevFest Karlsruhe
Page 49: Google Maps API - DevFest Karlsruhe

Locale

Page 50: Google Maps API - DevFest Karlsruhe
Page 51: Google Maps API - DevFest Karlsruhe
Page 53: Google Maps API - DevFest Karlsruhe

Styled Maps

Page 54: Google Maps API - DevFest Karlsruhe
Page 55: Google Maps API - DevFest Karlsruhe
Page 56: Google Maps API - DevFest Karlsruhe
Page 57: Google Maps API - DevFest Karlsruhe
Page 58: Google Maps API - DevFest Karlsruhe
Page 59: Google Maps API - DevFest Karlsruhe

var styles = [ { featureType: 'road', elementType: 'geometry', stylers: [ { hue: -45 }, { saturation: 100 } ] }];

var mapOptions = { ... styles: styles};

Page 60: Google Maps API - DevFest Karlsruhe
Page 61: Google Maps API - DevFest Karlsruhe
Page 62: Google Maps API - DevFest Karlsruhe

Natural Geography

Page 63: Google Maps API - DevFest Karlsruhe
Page 64: Google Maps API - DevFest Karlsruhe
Page 65: Google Maps API - DevFest Karlsruhe

Weather

Page 66: Google Maps API - DevFest Karlsruhe
Page 67: Google Maps API - DevFest Karlsruhe

var units = google.maps.weather.TemperatureUnit.FAHRENHEIT;

new google.maps.weather.CloudLayer({ map: map});

new google.maps.weather.WeatherLayer({ temperatureUnits: units, map: map});

Page 68: Google Maps API - DevFest Karlsruhe

BIG DATA

Page 69: Google Maps API - DevFest Karlsruhe

Clusterer

Page 70: Google Maps API - DevFest Karlsruhe
Page 72: Google Maps API - DevFest Karlsruhe

Fusion Tables

Page 73: Google Maps API - DevFest Karlsruhe
Page 74: Google Maps API - DevFest Karlsruhe
Page 75: Google Maps API - DevFest Karlsruhe

Heat Maps

Page 76: Google Maps API - DevFest Karlsruhe
Page 77: Google Maps API - DevFest Karlsruhe

var data = [ new google.maps.LatLng(37.782551, -122.445368), new google.maps.LatLng(37.782745, -122.444586), new google.maps.LatLng(37.782842, -122.443688), ...];

new google.maps.visualization.HeatmapLayer({ data: data});

Page 78: Google Maps API - DevFest Karlsruhe
Page 79: Google Maps API - DevFest Karlsruhe

Canvas Layer

Page 80: Google Maps API - DevFest Karlsruhe
Page 81: Google Maps API - DevFest Karlsruhe

github.com/ubilabs

Page 82: Google Maps API - DevFest Karlsruhe
Page 83: Google Maps API - DevFest Karlsruhe
Page 84: Google Maps API - DevFest Karlsruhe
Page 85: Google Maps API - DevFest Karlsruhe

Q&A

Page 86: Google Maps API - DevFest Karlsruhe
Page 87: Google Maps API - DevFest Karlsruhe

Martin Kleppe / Ubilabs

Google Maps API