Google Maps JS API

Alberto Simões
Alberto SimõesTeacher, programmer at University of Minho
Google Maps JS API
Alberto Simões ambs@di.uminho.pt
Terms of Use and Privacy
● Available both as free and paid services;
● Free service is limited:
○ 25 000 map loads per day.
○ soft quota.
● Needs service API key;
● Can be controlled per-host or using OAuth
credentials.
Obtaining an API Key
● Google APIs are controlled at https:
//console.developers.google.com
● Each API should be activated independently.
Obtaining an API Key
Basic HTML for Google Maps
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?
key=_KEY_&sensor=false">
</script>
Basic HTML for Google Maps
Basic HTML for Google Maps
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new
google.maps.LatLng(41.5442, -8.3219),
zoom: 3
};
...
Basic HTML for Google Maps
var map = new
google.maps.Map(
document.getElementById(
"map-canvas"
), mapOptions);
}
google.maps.event.addDomListener(
window, 'load', initialize);
</script>
Basic HTML for Google Maps
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
Basic HTML for Google Maps
Default UI
By default, Google Maps include:
● Zoom Control (enabled);
● Pan Control (enabled);
● Scale Control (disabled);
● Map Type Control (enabled);
● Street View Control (enabled);
● Rotate Control (enabled for 45º view);
● Overview Map Control (enabled…).
Disabling/Enabling the Default UI
Disabling completely the default behaviour:
function initialize() {
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
disableDefaultUI: true,
}
var map = new google.maps.Map(..., mapOptions);
}
Disabling/Enabling the Default UI
Controlling each UI object:
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
panControl: false, zoomControl: false,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false,
}
Disabling/Enabling the Default UI
Configuring the Default UI
Elements can be configured in different ways:
● Zoom Control have two different sizes;
● Map Type can be shown as a toolbar or a
drop-down menu;
● …
Elements can be placed in 8 different positions.
Configuring the Default UI
var mapOptions = {
center: new google.maps.LatLng(41.5442, -8.3219),
zoom: 3,
panControl: false, mapTypeControl: false,
streetViewControl: false, overviewMapControl: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER,
},
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT,
},
};
Configuring the Default UI
More on UI
It is possible to define custom buttons:
● based on XHTML and CSS;
● the control is pushed in a stack of controls in
the desired position;
● to the control is associated a javascript
method.
Using Markers
● Each mark is placed in a latitude/longitude;
● Markers have a specific title (tooltip);
● They can be removed;
● Support animations;
● Customizable to other icons;
Placing a Marker
<script type="text/javascript">
function initialize() {
var braga = new google.maps.LatLng(41.5442, -8.3219);
var mapOptions = { zoom: 8, center: braga };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: braga, map: map, title: "Braga"
});
}
google.maps.event.addDomListener(window, 'load',
initialize);
</script>
Placing a Marker
Removing a Marker when DblClicked
function initialize() {
var braga = new google.maps.LatLng(41.5345, -8.4250);
var mapOptions = { zoom: 8, center: braga };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var marker = new google.maps.Marker({
position: braga, map: map, title: "Braga"
});
google.maps.event.addListener(marker, ‘dblclick’,
function() { marker.setMap(null); });
}
Animating a Marker
function initialize() {
// ...
var marker = new google.maps.Marker({
position: braga, map: map, title: "Braga",
animation: google.maps.Animation.DROP,
});
google.maps.event.addListener(marker, 'click', function() {
if (marker.getAnimation() != null)
marker.setAnimation(null);
else
marker.setAnimation(google.maps.Animation.BOUNCE);
});
google.maps.event.addListener(marker, 'dblclick',
function() { marker.setMap(null); });
}
Custom Markers
function initialize() {
var braga = new google.maps.LatLng(41.5345, -8.4250);
var mapOptions = { zoom: 8, center: braga };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var image = "icon.png";
var marker = new google.maps.Marker({
position: braga,
map: map,
title: "Braga",
icon: image,
});
}
Custom Markers
Info Windows
● Present geo-referenced text in a small
window;
● Usually they are placed with a marker;
● But can be placed directly on a
latitude/longitude object.
● Can contain any HTML content. You can
force its width by CSS.
Info Window at Marker
function initialize() {
var braga = new google.maps.LatLng(41.5345, -8.4250);
var mapOptions = { center: braga, zoom: 10 };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var infowindow = new google.maps.InfoWindow( {
content: '<div id="content">some <b>HTML</b></div>’,
maxWidth: 200,
});
var marker = new google.maps.Marker( {
position: braga, map: map, title: 'Braga'
});
google.maps.event.addListener(marker, 'click',
function() { infowindow.open(map, marker); });
}
Info Window at Marker
Info Window at LatLng object
function initialize() {
var braga = new google.maps.LatLng(41.5345, -8.4250);
var mapOptions = { center: braga, zoom: 10 };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var infowindow = new google.maps.InfoWindow( {
position: braga,
content: '<div id="content">some <b>HTML</b></div>’,
maxWidth: 200,
});
infowindow.open(map, marker);
}
Info Window at LatLng object
Closing Info Window
...
var infowindow = new google.maps.InfoWindow( {
content: '<div id="content">some <b>HTML</b></div>’,
maxWidth: 200,
});
var marker = new google.maps.Marker( {
position: braga, map: map, title: 'Braga'
});
google.maps.event.addListener(marker, 'click',
function() { infowindow.open(map, marker); });
google.maps.event.addListener(marker, 'dblclick',
function() { infowindow.close(); });
}
Drawing on a Map
● Can draw:
● Lines;
● Polylines;
● Circles;
● Rectangles.
● These shapes can be configured to be
draggable and editable by users.
Drawing a Polyline
function initialize() {
var braga = new google.maps.LatLng(41.5645, -8.4250);
var mapOptions = { center: braga, zoom: 10 };
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
var lineCoords = [ braga,
new google.maps.LatLng(41.5000, -8.4250),
new google.maps.LatLng(41.5000, -8.3500),
new google.maps.LatLng(41.4500, -8.3000) ];
var line = new google.maps.Polyline({
path: lineCoords, strokeColor: '#FF0000',
strokeOpacity: 0.5, strokeWeight: 20,
});
line.setMap(map);
}
Drawing a Polyline
Services: Overview
● Directions
● Distances
● Elevation
● GeoCoding
● Maximum Zoom Imagery
● Street View
● Libraries
○ Places, AdSense, Panoramio, ...
GeoCoding Service
● Allows the conversion of a text address in its
LatLng coordinates,
● Allows the conversion of a coordinate pair
into a text address:
○ At different levels
■ Street
■ County
■ State
■ Country
GeoCoding Request
A GeoCoding request looks like:
{
address: string, // These two are required
location: LatLng,// and mutually exclusive
bounds: LatLngBounds,
region: string
}
GeoCoding Response
A GeoCoding response looks like:
results[]: {
types[]: string, formatted_address: string,
address_components[]: {
short_name: string, long_name: string,
postcode_localities[]: string, types[]: string
},
partial_match: boolean,
geometry: {
location: LatLng, location_type:
GeocoderLocationType
viewport: LatLngBounds, bounds: LatLngBounds
}
}
GeoCoding Example
Given a click on a map:
1) get the LatLng coordinates,
2) get the country name they belong to.
GeoCoding Example
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(41.5442, -8.3219),
zoom: 3
};
var map = new google.maps.Map(
document.getElementById("map-canvas"), mapOptions);
...
GeoCoding Example
...
google.maps.event.addListener(map, 'click',
function (event) {
var coder = new google.maps.Geocoder();
var request = { location: event.latLng };
coder.geocode(request,
function (results, status) {
if (status == "OK") {
var country = guessCountry(results);
alert(country);
} else {
alert(“no country?”);
}
});
});
} /* end initialize */
GeoCoding Example
function guessCountry(geocoderResults) {
for (var i = 0; i < geocoderResults.length; i++) {
var res = geocoderResults[i];
for (var j = 0; j < res.address_components.length; j++){
var comp = res.address_components[j];
if (jQuery.inArray("country", comp.types) >= 0) {
return comp.long_name;
}
}
}
return "??";
}
To use jQuery in need to include it:
<script src="http://code.jquery.com/jquery-1.11.0.min.js">
</script>
GeoCoding Example
Fusion Tables Introduction
● Fusion tables are a relational database;
● Each user can create and share tables;
● There are tables with relevant information:
○ butterflies species in USA;
○ countries and their number of inhabitants;
○ and many other userfull and futile information.
A Relevant Fusion Table...
Table id: 12e2VhiXyMzHWDl6aponObHH_gvlMDoac9RTrcJ0
A Relevant Fusion Table...
A Relevant Fusion Table...
A Relevant Fusion Table...
A Relevant Fusion Table...
Fusion Tables Layers
It is possible to render KML over a map.
Example: Given a click on a map:
1) get the LatLng coordinates,
2) get the country name they belong to.
3) draw it over the map
4) new clicks remove the country draw,
...and starts again (goto 1).
Fusion Tables Layers
// define this outside
var layer = null;
Fusion Tables Layers
google.maps.event.addListener(map, 'click',
function (event) {
var coder = new google.maps.Geocoder();
var request = { location: event.latLng };
coder.geocode(request, function (results, status) {
if (status == "OK") {
var country = guessCountry(results);
if (layer != null) { layer.setMap(null); }
layer = new google.maps.FusionTablesLayer({
query: { select: 'geometry',
from: '12e2VhiXyMzHWDl6aponObHH_gvlMDoac9RTrcJ0',
where: "name = '" + country + "'", },
});
layer.setMap(map);
} }); });
Fusion Tables Layers
Reference
https://developers.google.
com/maps/documentation/javascript/3.
exp/reference
Google Maps JS API
Alberto Simões ambs@di.uminho.pt
1 of 55

Recommended

Google maps api 3 by
Google maps api 3Google maps api 3
Google maps api 3Muhammad Younis
2.1K views80 slides
Google Maps API by
Google Maps APIGoogle Maps API
Google Maps APIDave Ross
2.4K views22 slides
Google Maps API by
Google Maps APIGoogle Maps API
Google Maps APIM A Hossain Tonu
6K views28 slides
Google Map API by
Google Map APIGoogle Map API
Google Map APIM A Hossain Tonu
3.6K views28 slides
Google Maps API by
Google Maps APIGoogle Maps API
Google Maps APIM A Hossain Tonu
3.6K views28 slides
Grails : Ordr, Maps & Charts by
Grails : Ordr, Maps & ChartsGrails : Ordr, Maps & Charts
Grails : Ordr, Maps & ChartsHenk Jurriens
524 views25 slides

More Related Content

What's hot

Mapathon 2013 - Google Maps Javascript API by
Mapathon 2013 - Google Maps Javascript APIMapathon 2013 - Google Maps Javascript API
Mapathon 2013 - Google Maps Javascript APINAILBITER
1.9K views40 slides
Intro To Google Maps by
Intro To Google MapsIntro To Google Maps
Intro To Google MapsEric ShangKuan
1K views22 slides
Google Maps API 101 by
Google Maps API 101Google Maps API 101
Google Maps API 101Sebastian Roming
854 views15 slides
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico) by
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)Ossama Alami
895 views37 slides
51811680 open layers by
51811680 open layers51811680 open layers
51811680 open layersGien Rockmantic
2K views36 slides
Drupal and the GeoSpatial Web by
Drupal and the GeoSpatial WebDrupal and the GeoSpatial Web
Drupal and the GeoSpatial WebAndrew Turner
4.1K views137 slides

What's hot(12)

Mapathon 2013 - Google Maps Javascript API by NAILBITER
Mapathon 2013 - Google Maps Javascript APIMapathon 2013 - Google Maps Javascript API
Mapathon 2013 - Google Maps Javascript API
NAILBITER1.9K views
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico) by Ossama Alami
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)
Performance and Scalability for Maps API Sites (Dev Fest '10 Mexico)
Ossama Alami895 views
Drupal and the GeoSpatial Web by Andrew Turner
Drupal and the GeoSpatial WebDrupal and the GeoSpatial Web
Drupal and the GeoSpatial Web
Andrew Turner4.1K views
Of Nodes and Maps (Web Mapping with Drupal - Part II) by Ranel Padon
Of Nodes and Maps (Web Mapping with Drupal - Part II)Of Nodes and Maps (Web Mapping with Drupal - Part II)
Of Nodes and Maps (Web Mapping with Drupal - Part II)
Ranel Padon9.4K views
Getting Oriented with MapKit: Everything you need to get started with the new... by John Wilker
Getting Oriented with MapKit: Everything you need to get started with the new...Getting Oriented with MapKit: Everything you need to get started with the new...
Getting Oriented with MapKit: Everything you need to get started with the new...
John Wilker3K views

Viewers also liked

Ubilabs: Google Maps API - Best Practices by
Ubilabs: Google Maps API - Best PracticesUbilabs: Google Maps API - Best Practices
Ubilabs: Google Maps API - Best PracticesMartin Kleppe
4.3K views98 slides
Google Maps API for Android by
Google Maps API for AndroidGoogle Maps API for Android
Google Maps API for AndroidMaksim Golivkin
7.7K views20 slides
Google Maps Presentation by
Google Maps PresentationGoogle Maps Presentation
Google Maps PresentationDavid Kamerer
16.3K views14 slides
CSS3 and a brief introduction to Google Maps API v3 by
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 Jeffrey Barke
1.2K views23 slides
Geolocation and Mapping by
Geolocation and MappingGeolocation and Mapping
Geolocation and MappingIvano Malavolta
2.7K views67 slides
Google Maps API by
Google Maps APIGoogle Maps API
Google Maps APIhchen1
1.4K views18 slides

Viewers also liked(20)

Ubilabs: Google Maps API - Best Practices by Martin Kleppe
Ubilabs: Google Maps API - Best PracticesUbilabs: Google Maps API - Best Practices
Ubilabs: Google Maps API - Best Practices
Martin Kleppe4.3K views
Google Maps Presentation by David Kamerer
Google Maps PresentationGoogle Maps Presentation
Google Maps Presentation
David Kamerer16.3K views
CSS3 and a brief introduction to Google Maps API v3 by Jeffrey Barke
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
Jeffrey Barke1.2K views
Google Maps API by hchen1
Google Maps APIGoogle Maps API
Google Maps API
hchen11.4K views
Geolocation and mapping using Google Maps services by Ivano Malavolta
Geolocation and mapping using Google Maps servicesGeolocation and mapping using Google Maps services
Geolocation and mapping using Google Maps services
Ivano Malavolta9.3K views
Google Maps by gp3project
Google MapsGoogle Maps
Google Maps
gp3project18.7K views
Google Maps API - DevFest Karlsruhe by Martin Kleppe
Google Maps API - DevFest Karlsruhe Google Maps API - DevFest Karlsruhe
Google Maps API - DevFest Karlsruhe
Martin Kleppe23.8K views
Technology's New Role in Healthcare by Primacy
Technology's New Role in HealthcareTechnology's New Role in Healthcare
Technology's New Role in Healthcare
Primacy17.4K views
MySql slides (ppt) by webhostingguy
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
webhostingguy32.7K views
Introduction to PHP by Bradley Holt
Introduction to PHPIntroduction to PHP
Introduction to PHP
Bradley Holt42.6K views
PHP Powerpoint -- Teach PHP with this by Ian Macali
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
Ian Macali54K views

Similar to Google Maps JS API

Google Maps Api by
Google Maps ApiGoogle Maps Api
Google Maps ApiAnas Alpure
594 views45 slides
How Quick Can We Be? Data Visualization Techniques for Engineers. by
How Quick Can We Be? Data Visualization Techniques for Engineers. How Quick Can We Be? Data Visualization Techniques for Engineers.
How Quick Can We Be? Data Visualization Techniques for Engineers. Avni Khatri
1.6K views92 slides
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece by
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece CoLab Athens
1.7K views42 slides
How data rules the world: Telemetry in Battlefield Heroes by
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield HeroesElectronic Arts / DICE
4.6K views26 slides
Gmaps Railscamp2008 by
Gmaps Railscamp2008Gmaps Railscamp2008
Gmaps Railscamp2008xilinus
839 views24 slides
Barcamp GoogleMaps - praktické ukázky kódu by
Barcamp GoogleMaps - praktické ukázky kóduBarcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kóduMilos Lenoch
686 views13 slides

Similar to Google Maps JS API(20)

How Quick Can We Be? Data Visualization Techniques for Engineers. by Avni Khatri
How Quick Can We Be? Data Visualization Techniques for Engineers. How Quick Can We Be? Data Visualization Techniques for Engineers.
How Quick Can We Be? Data Visualization Techniques for Engineers.
Avni Khatri1.6K views
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece by CoLab Athens
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece
Ioannis Doxaras on GIS and Gmaps at 1st GTUG meetup Greece
CoLab Athens1.7K views
How data rules the world: Telemetry in Battlefield Heroes by Electronic Arts / DICE
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield Heroes
Gmaps Railscamp2008 by xilinus
Gmaps Railscamp2008Gmaps Railscamp2008
Gmaps Railscamp2008
xilinus839 views
Barcamp GoogleMaps - praktické ukázky kódu by Milos Lenoch
Barcamp GoogleMaps - praktické ukázky kóduBarcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kódu
Milos Lenoch686 views
Das Web Wird Mobil - Geolocation und Location Based Services by Stephan Schmidt
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
Stephan Schmidt3K views
Sapo GIS Hands-On by codebits
Sapo GIS Hands-OnSapo GIS Hands-On
Sapo GIS Hands-On
codebits464 views
Gis SAPO Hands On by codebits
Gis SAPO Hands OnGis SAPO Hands On
Gis SAPO Hands On
codebits555 views
Adobe MAX 2009: Making Maps with Flash by Ossama Alami
Adobe MAX 2009: Making Maps with FlashAdobe MAX 2009: Making Maps with Flash
Adobe MAX 2009: Making Maps with Flash
Ossama Alami882 views
Hands on with the Google Maps Data API by ss318
Hands on with the Google Maps Data APIHands on with the Google Maps Data API
Hands on with the Google Maps Data API
ss3181.2K views
โค๊ดที่ใช้ทำ Custom markers หรือการปักหมุด by ranggo24
โค๊ดที่ใช้ทำ Custom markers หรือการปักหมุดโค๊ดที่ใช้ทำ Custom markers หรือการปักหมุด
โค๊ดที่ใช้ทำ Custom markers หรือการปักหมุด
ranggo24179 views
Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042) by Kanika Garg
Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042)Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042)
Google Chart Tools Kanika Garg (10BM60035) Lavanya R. (10BM60042)
Kanika Garg1K views
Developing Spatial Applications with Google Maps and CARTO by CARTO
Developing Spatial Applications with Google Maps and CARTODeveloping Spatial Applications with Google Maps and CARTO
Developing Spatial Applications with Google Maps and CARTO
CARTO259 views
Google Chart Tools by Kanika Garg
Google Chart Tools Google Chart Tools
Google Chart Tools
Kanika Garg8K views
Google Mapy (Jaroslav Bengl) by Jiří Šmída
Google Mapy (Jaroslav Bengl)Google Mapy (Jaroslav Bengl)
Google Mapy (Jaroslav Bengl)
Jiří Šmída2.6K views

More from Alberto Simões

Source Code Quality by
Source Code QualitySource Code Quality
Source Code QualityAlberto Simões
1.6K views61 slides
Language Identification: A neural network approach by
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approachAlberto Simões
2.2K views40 slides
Making the most of a 100-year-old dictionary by
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionaryAlberto Simões
1.5K views42 slides
Dictionary Alignment by Rewrite-based Entry Translation by
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry TranslationAlberto Simões
903 views23 slides
EMLex-A5: Specialized Dictionaries by
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized DictionariesAlberto Simões
2.9K views150 slides
Modelação de Dados by
Modelação de DadosModelação de Dados
Modelação de DadosAlberto Simões
5.8K views61 slides

More from Alberto Simões(20)

Language Identification: A neural network approach by Alberto Simões
Language Identification: A neural network approachLanguage Identification: A neural network approach
Language Identification: A neural network approach
Alberto Simões2.2K views
Making the most of a 100-year-old dictionary by Alberto Simões
Making the most of a 100-year-old dictionaryMaking the most of a 100-year-old dictionary
Making the most of a 100-year-old dictionary
Alberto Simões1.5K views
Dictionary Alignment by Rewrite-based Entry Translation by Alberto Simões
Dictionary Alignment by Rewrite-based Entry TranslationDictionary Alignment by Rewrite-based Entry Translation
Dictionary Alignment by Rewrite-based Entry Translation
Alberto Simões903 views
EMLex-A5: Specialized Dictionaries by Alberto Simões
EMLex-A5: Specialized DictionariesEMLex-A5: Specialized Dictionaries
EMLex-A5: Specialized Dictionaries
Alberto Simões2.9K views
Aula 04 - Introdução aos Diagramas de Sequência by Alberto Simões
Aula 04 - Introdução aos Diagramas de SequênciaAula 04 - Introdução aos Diagramas de Sequência
Aula 04 - Introdução aos Diagramas de Sequência
Alberto Simões1.2K views
Aula 03 - Introdução aos Diagramas de Atividade by Alberto Simões
Aula 03 - Introdução aos Diagramas de AtividadeAula 03 - Introdução aos Diagramas de Atividade
Aula 03 - Introdução aos Diagramas de Atividade
Alberto Simões3.8K views
Aula 02 - Engenharia de Requisitos by Alberto Simões
Aula 02 - Engenharia de RequisitosAula 02 - Engenharia de Requisitos
Aula 02 - Engenharia de Requisitos
Alberto Simões1.6K views
Aula 01 - Planeamento de Sistemas de Informação by Alberto Simões
Aula 01 - Planeamento de Sistemas de InformaçãoAula 01 - Planeamento de Sistemas de Informação
Aula 01 - Planeamento de Sistemas de Informação
Alberto Simões4.4K views
Building C and C++ libraries with Perl by Alberto Simões
Building C and C++ libraries with PerlBuilding C and C++ libraries with Perl
Building C and C++ libraries with Perl
Alberto Simões1.6K views
Processing XML: a rewriting system approach by Alberto Simões
Processing XML: a rewriting system approachProcessing XML: a rewriting system approach
Processing XML: a rewriting system approach
Alberto Simões854 views
Arquitecturas de Tradução Automática by Alberto Simões
Arquitecturas de Tradução AutomáticaArquitecturas de Tradução Automática
Arquitecturas de Tradução Automática
Alberto Simões751 views
Extracção de Recursos para Tradução Automática by Alberto Simões
Extracção de Recursos para Tradução AutomáticaExtracção de Recursos para Tradução Automática
Extracção de Recursos para Tradução Automática
Alberto Simões677 views

Recently uploaded

PORTFOLIO 1 (Bret Michael Pepito).pdf by
PORTFOLIO 1 (Bret Michael Pepito).pdfPORTFOLIO 1 (Bret Michael Pepito).pdf
PORTFOLIO 1 (Bret Michael Pepito).pdfbrejess0410
9 views6 slides
Building trust in our information ecosystem: who do we trust in an emergency by
Building trust in our information ecosystem: who do we trust in an emergencyBuilding trust in our information ecosystem: who do we trust in an emergency
Building trust in our information ecosystem: who do we trust in an emergencyTina Purnat
109 views18 slides
Marketing and Community Building in Web3 by
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3Federico Ast
14 views64 slides
WEB 2.O TOOLS: Empowering education.pptx by
WEB 2.O TOOLS: Empowering education.pptxWEB 2.O TOOLS: Empowering education.pptx
WEB 2.O TOOLS: Empowering education.pptxnarmadhamanohar21
16 views16 slides
IETF 118: Starlink Protocol Performance by
IETF 118: Starlink Protocol PerformanceIETF 118: Starlink Protocol Performance
IETF 118: Starlink Protocol PerformanceAPNIC
394 views22 slides
information by
informationinformation
informationkhelgishekhar
10 views4 slides

Recently uploaded(10)

PORTFOLIO 1 (Bret Michael Pepito).pdf by brejess0410
PORTFOLIO 1 (Bret Michael Pepito).pdfPORTFOLIO 1 (Bret Michael Pepito).pdf
PORTFOLIO 1 (Bret Michael Pepito).pdf
brejess04109 views
Building trust in our information ecosystem: who do we trust in an emergency by Tina Purnat
Building trust in our information ecosystem: who do we trust in an emergencyBuilding trust in our information ecosystem: who do we trust in an emergency
Building trust in our information ecosystem: who do we trust in an emergency
Tina Purnat109 views
Marketing and Community Building in Web3 by Federico Ast
Marketing and Community Building in Web3Marketing and Community Building in Web3
Marketing and Community Building in Web3
Federico Ast14 views
IETF 118: Starlink Protocol Performance by APNIC
IETF 118: Starlink Protocol PerformanceIETF 118: Starlink Protocol Performance
IETF 118: Starlink Protocol Performance
APNIC394 views
The Dark Web : Hidden Services by Anshu Singh
The Dark Web : Hidden ServicesThe Dark Web : Hidden Services
The Dark Web : Hidden Services
Anshu Singh5 views
How to think like a threat actor for Kubernetes.pptx by LibbySchulze1
How to think like a threat actor for Kubernetes.pptxHow to think like a threat actor for Kubernetes.pptx
How to think like a threat actor for Kubernetes.pptx
LibbySchulze15 views

Google Maps JS API

  • 1. Google Maps JS API Alberto Simões ambs@di.uminho.pt
  • 2. Terms of Use and Privacy ● Available both as free and paid services; ● Free service is limited: ○ 25 000 map loads per day. ○ soft quota. ● Needs service API key; ● Can be controlled per-host or using OAuth credentials.
  • 3. Obtaining an API Key ● Google APIs are controlled at https: //console.developers.google.com ● Each API should be activated independently.
  • 5. Basic HTML for Google Maps <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map-canvas { height: 100% } </style>
  • 7. Basic HTML for Google Maps <script type="text/javascript"> function initialize() { var mapOptions = { center: new google.maps.LatLng(41.5442, -8.3219), zoom: 3 }; ...
  • 8. Basic HTML for Google Maps var map = new google.maps.Map( document.getElementById( "map-canvas" ), mapOptions); } google.maps.event.addDomListener( window, 'load', initialize); </script>
  • 9. Basic HTML for Google Maps </head> <body> <div id="map-canvas"/> </body> </html>
  • 10. Basic HTML for Google Maps
  • 11. Default UI By default, Google Maps include: ● Zoom Control (enabled); ● Pan Control (enabled); ● Scale Control (disabled); ● Map Type Control (enabled); ● Street View Control (enabled); ● Rotate Control (enabled for 45º view); ● Overview Map Control (enabled…).
  • 12. Disabling/Enabling the Default UI Disabling completely the default behaviour: function initialize() { var mapOptions = { zoom: 4, center: new google.maps.LatLng(-33, 151), disableDefaultUI: true, } var map = new google.maps.Map(..., mapOptions); }
  • 13. Disabling/Enabling the Default UI Controlling each UI object: var mapOptions = { zoom: 4, center: new google.maps.LatLng(-33, 151), panControl: false, zoomControl: false, mapTypeControl: false, scaleControl: false, streetViewControl: false, overviewMapControl: false, }
  • 15. Configuring the Default UI Elements can be configured in different ways: ● Zoom Control have two different sizes; ● Map Type can be shown as a toolbar or a drop-down menu; ● … Elements can be placed in 8 different positions.
  • 16. Configuring the Default UI var mapOptions = { center: new google.maps.LatLng(41.5442, -8.3219), zoom: 3, panControl: false, mapTypeControl: false, streetViewControl: false, overviewMapControl: false, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE, position: google.maps.ControlPosition.LEFT_CENTER, }, scaleControl: true, scaleControlOptions: { position: google.maps.ControlPosition.TOP_LEFT, }, };
  • 18. More on UI It is possible to define custom buttons: ● based on XHTML and CSS; ● the control is pushed in a stack of controls in the desired position; ● to the control is associated a javascript method.
  • 19. Using Markers ● Each mark is placed in a latitude/longitude; ● Markers have a specific title (tooltip); ● They can be removed; ● Support animations; ● Customizable to other icons;
  • 20. Placing a Marker <script type="text/javascript"> function initialize() { var braga = new google.maps.LatLng(41.5442, -8.3219); var mapOptions = { zoom: 8, center: braga }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var marker = new google.maps.Marker({ position: braga, map: map, title: "Braga" }); } google.maps.event.addDomListener(window, 'load', initialize); </script>
  • 22. Removing a Marker when DblClicked function initialize() { var braga = new google.maps.LatLng(41.5345, -8.4250); var mapOptions = { zoom: 8, center: braga }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var marker = new google.maps.Marker({ position: braga, map: map, title: "Braga" }); google.maps.event.addListener(marker, ‘dblclick’, function() { marker.setMap(null); }); }
  • 23. Animating a Marker function initialize() { // ... var marker = new google.maps.Marker({ position: braga, map: map, title: "Braga", animation: google.maps.Animation.DROP, }); google.maps.event.addListener(marker, 'click', function() { if (marker.getAnimation() != null) marker.setAnimation(null); else marker.setAnimation(google.maps.Animation.BOUNCE); }); google.maps.event.addListener(marker, 'dblclick', function() { marker.setMap(null); }); }
  • 24. Custom Markers function initialize() { var braga = new google.maps.LatLng(41.5345, -8.4250); var mapOptions = { zoom: 8, center: braga }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var image = "icon.png"; var marker = new google.maps.Marker({ position: braga, map: map, title: "Braga", icon: image, }); }
  • 26. Info Windows ● Present geo-referenced text in a small window; ● Usually they are placed with a marker; ● But can be placed directly on a latitude/longitude object. ● Can contain any HTML content. You can force its width by CSS.
  • 27. Info Window at Marker function initialize() { var braga = new google.maps.LatLng(41.5345, -8.4250); var mapOptions = { center: braga, zoom: 10 }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var infowindow = new google.maps.InfoWindow( { content: '<div id="content">some <b>HTML</b></div>’, maxWidth: 200, }); var marker = new google.maps.Marker( { position: braga, map: map, title: 'Braga' }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); }
  • 28. Info Window at Marker
  • 29. Info Window at LatLng object function initialize() { var braga = new google.maps.LatLng(41.5345, -8.4250); var mapOptions = { center: braga, zoom: 10 }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var infowindow = new google.maps.InfoWindow( { position: braga, content: '<div id="content">some <b>HTML</b></div>’, maxWidth: 200, }); infowindow.open(map, marker); }
  • 30. Info Window at LatLng object
  • 31. Closing Info Window ... var infowindow = new google.maps.InfoWindow( { content: '<div id="content">some <b>HTML</b></div>’, maxWidth: 200, }); var marker = new google.maps.Marker( { position: braga, map: map, title: 'Braga' }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); }); google.maps.event.addListener(marker, 'dblclick', function() { infowindow.close(); }); }
  • 32. Drawing on a Map ● Can draw: ● Lines; ● Polylines; ● Circles; ● Rectangles. ● These shapes can be configured to be draggable and editable by users.
  • 33. Drawing a Polyline function initialize() { var braga = new google.maps.LatLng(41.5645, -8.4250); var mapOptions = { center: braga, zoom: 10 }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); var lineCoords = [ braga, new google.maps.LatLng(41.5000, -8.4250), new google.maps.LatLng(41.5000, -8.3500), new google.maps.LatLng(41.4500, -8.3000) ]; var line = new google.maps.Polyline({ path: lineCoords, strokeColor: '#FF0000', strokeOpacity: 0.5, strokeWeight: 20, }); line.setMap(map); }
  • 35. Services: Overview ● Directions ● Distances ● Elevation ● GeoCoding ● Maximum Zoom Imagery ● Street View ● Libraries ○ Places, AdSense, Panoramio, ...
  • 36. GeoCoding Service ● Allows the conversion of a text address in its LatLng coordinates, ● Allows the conversion of a coordinate pair into a text address: ○ At different levels ■ Street ■ County ■ State ■ Country
  • 37. GeoCoding Request A GeoCoding request looks like: { address: string, // These two are required location: LatLng,// and mutually exclusive bounds: LatLngBounds, region: string }
  • 38. GeoCoding Response A GeoCoding response looks like: results[]: { types[]: string, formatted_address: string, address_components[]: { short_name: string, long_name: string, postcode_localities[]: string, types[]: string }, partial_match: boolean, geometry: { location: LatLng, location_type: GeocoderLocationType viewport: LatLngBounds, bounds: LatLngBounds } }
  • 39. GeoCoding Example Given a click on a map: 1) get the LatLng coordinates, 2) get the country name they belong to.
  • 40. GeoCoding Example function initialize() { var mapOptions = { center: new google.maps.LatLng(41.5442, -8.3219), zoom: 3 }; var map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions); ...
  • 41. GeoCoding Example ... google.maps.event.addListener(map, 'click', function (event) { var coder = new google.maps.Geocoder(); var request = { location: event.latLng }; coder.geocode(request, function (results, status) { if (status == "OK") { var country = guessCountry(results); alert(country); } else { alert(“no country?”); } }); }); } /* end initialize */
  • 42. GeoCoding Example function guessCountry(geocoderResults) { for (var i = 0; i < geocoderResults.length; i++) { var res = geocoderResults[i]; for (var j = 0; j < res.address_components.length; j++){ var comp = res.address_components[j]; if (jQuery.inArray("country", comp.types) >= 0) { return comp.long_name; } } } return "??"; } To use jQuery in need to include it: <script src="http://code.jquery.com/jquery-1.11.0.min.js"> </script>
  • 44. Fusion Tables Introduction ● Fusion tables are a relational database; ● Each user can create and share tables; ● There are tables with relevant information: ○ butterflies species in USA; ○ countries and their number of inhabitants; ○ and many other userfull and futile information.
  • 45. A Relevant Fusion Table... Table id: 12e2VhiXyMzHWDl6aponObHH_gvlMDoac9RTrcJ0
  • 46. A Relevant Fusion Table...
  • 47. A Relevant Fusion Table...
  • 48. A Relevant Fusion Table...
  • 49. A Relevant Fusion Table...
  • 50. Fusion Tables Layers It is possible to render KML over a map. Example: Given a click on a map: 1) get the LatLng coordinates, 2) get the country name they belong to. 3) draw it over the map 4) new clicks remove the country draw, ...and starts again (goto 1).
  • 51. Fusion Tables Layers // define this outside var layer = null;
  • 52. Fusion Tables Layers google.maps.event.addListener(map, 'click', function (event) { var coder = new google.maps.Geocoder(); var request = { location: event.latLng }; coder.geocode(request, function (results, status) { if (status == "OK") { var country = guessCountry(results); if (layer != null) { layer.setMap(null); } layer = new google.maps.FusionTablesLayer({ query: { select: 'geometry', from: '12e2VhiXyMzHWDl6aponObHH_gvlMDoac9RTrcJ0', where: "name = '" + country + "'", }, }); layer.setMap(map); } }); });
  • 55. Google Maps JS API Alberto Simões ambs@di.uminho.pt