1 of 27

Google Maps API

Dawid Ostrowski

dos@google.com

gplus.name/ostrowski

www.dawidostrowski.pl

2 of 27

Inspiration

3 of 27

Do you need your own maps?

4 of 27

Useful URLs

5 of 27

Be creative!

  • Create / use your own data
  • Try to find open data
  • Use data from your neighborhood
  • Make your maps beautiful
  • We have data
    • Małopolska API
    • Nowe Zabłocie

https://sites.google.com/site/ostrowskionline/technologie/google-maps/dane

6 of 27

Usage limits

7 of 27

Obtaining an API key

To create your API key:

  • Visit the APIs Console at https://code.google.com/apis/console and log in with your Google Account.
  • Create a new project if necessary
  • Click the Services link from the left-hand menu.
  • Activate the Google Maps API v3 service.
  • Click the API Access link from the left-hand menu. Your API key is available from the API Access page, in the Simple API Access section. Maps API applications use the Key for browser apps.
  • You can specify which domains are allowed to use your API key by clicking the Edit allowed referrers

8 of 27

Obtaining an API key

9 of 27

Initialization

  • Declare the app as HTML5
  • Create a <div> to be a map container
  • Load Google Maps API providing key and sensor parameters
  • Create mapOptions object with properties:
    • center
    • zoom
    • mapTypeId
  • Create google.maps.Map object passing div container and mapOptions as parameters

https://developers.google.com/maps/documentation/javascript/tutorial?hl=pl

https://developers.google.com/maps/documentation/javascript/training/fundamentals/adding-a-google-map

10 of 27

Localization

  • Language localization
    • <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&language=ja">
  • Region localization
    • <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&region=GB">

11 of 27

Basic elements of the API

12 of 27

Overlays

  • Markers
  • Info windows
  • Symbols
  • Polylines
  • Polygons
  • Circles and Rectangles
  • User-Editable shapes
  • Drawing library
  • Ground and custom overlays

13 of 27

Markers

14 of 27

Symbols

  • Symbol is a vector based image
  • Can be displayed on Marker or Polyline object
  • Defined by path - using SVG path notation
  • Several predefined symbols are available via the SymbolPath class

15 of 27

Info Windows

  • google.maps.InfoWindow
  • google.maps.InfoWindowOptions
  • google.maps.event.addListener(MARKER, EVENT, CALLBACK_FUNCTION)
  • content may contain:
    • simple text
    • HTML snippet
    • DOM element

16 of 27

Polylines

  • Polyline consists of an array of LatLng locations
  • Styling
    • strokeColor
    • strokeOpacity
    • strokeWeight
  • might be editable by users

https://developers.google.com/maps/documentation/javascript/overlays?hl=pl#PolylineSymbols

17 of 27

Polyline arrays

  • Polyline's method getPath() returns array of type MVCArray
  • Available operation of MVCArray
    • getAt()
    • insertAt()
    • removeAt()

https://developers.google.com/maps/documentation/javascript/overlays?hl=pl#PolylineArrays

18 of 27

Symbols on Polylines

  • Add vector based images (symbols) to a polyline
  • Set the icons[] property of the PolylineOptions
  • Elements of icons[] - IconSequence
    • fixedRotation
    • icon
    • offset
    • repeat
  • Animate by changing offset

https://developers.google.com/maps/documentation/javascript/overlays?hl=pl#PolylineSymbols

19 of 27

Polygons

  • Similar to Polyline but instead of being open-ended, polygons define regions within a closed loop
  • Complex shapes, discontinuities, "donuts", intersections
  • May be editable
  • Contain multiple paths
  • paths property specifies an "array of arrays"

https://developers.google.com/maps/documentation/javascript/overlays?hl=pl#Polygons

20 of 27

Circles and Rectangles

  • Circle and Rectangle simplified classes
  • No need to define paths
  • May be editable
  • Circle
    • center (google.maps.LatLng)
    • radius (in meters)
  • Rectangle
    • bounds (google.maps.LatLngBounds)

21 of 27

Geocoding

  • Convert address "Rynek Główny 12, Kraków, Polska" into geographic coordinates (50.06061,19.937954)
  • For static, known addresses use web service
  • It's asynchronous - you need to pass a callback method
  • Geocoder, GeocoderRequest, GeocoderResult
  • geocoder.geocode - with 'address' attribute

22 of 27

Reverse geocoding

  • Convert geographic coordinates into a human-readable address
  • geocoder.geocode - with 'latLng' attribute

23 of 27

Events

  • User events (such as 'click' mouse events)
  • Changes in Maps API (MVC state change notifications) property_changed
  • Register addListener() or addDomListener() on google.maps.event namespace

https://developers.google.com/maps/documentation/javascript/events

24 of 27

Controls

  • Disable / enable controls on the map
  • Control positioning
  • Custom controls
  • Custom controls with state

https://developers.google.com/maps/documentation/javascript/controls?hl=pl

25 of 27

Styles

  • Changing default styles (changing the default map style)
  • Creating styledmap type

http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html

https://developers.google.com/maps/documentation/javascript/styling?hl=pl#styling_the_default_map

https://developers.google.com/maps/documentation/javascript/styling?hl=pl#creating_a_styledMapType

26 of 27

Layers (HeatmapLayer)

  • Load google.maps.visualization
  • Color overlay depicts the intensity of data at geographical points
  • Client side (Heatmap Layer)
  • Server side (Fusion table)
  • Create HeatmapLayer object, provide it with some data and add it to the map
  • Data in the form of LatLng or WeighedLocation objects

https://developers.google.com/maps/documentation/javascript/layers?hl=pl#JSHeatMaps

https://developers.google.com/maps/documentation/javascript/libraries?hl=pl

27 of 27

Thank you

Let's get to work :)