{"id":1097,"date":"2014-10-31T15:23:56","date_gmt":"2014-10-31T13:23:56","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=1097"},"modified":"2017-12-19T15:41:03","modified_gmt":"2017-12-19T13:41:03","slug":"html5-geolocation-api-with-google-maps","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/","title":{"rendered":"HTML5 Geolocation API with Google Maps"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/i1.wp.com\/www.w3.org\/html\/logo\/downloads\/HTML5_Logo_512.png?resize=150%2C150\" alt=\"\" align=\"right\" \/>I have been reading <a href=\"http:\/\/www.flipkart.com\/head-first-html5-programming-1st\/p\/itmd45dxk5m6sg7k?pid=9789350235324&amp;affid=INMohamblo\" target=\"_blank\">Head First HTML5<\/a> and read about the Geolocation support in <a href=\"http:\/\/www.html5rocks.com\/en\/\" target=\"_blank\">HTML5<\/a> and also went through the example they have shared about using the <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/tutorial\" target=\"_blank\">Google Maps<\/a> with HTML5 geolocation API.<\/p>\n<p>It was an interesting example and I went a step further and enhanced the example to show some eat outs around the current location. For this I made use of the <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/places\" target=\"_blank\">Places library<\/a> which comes with the Google Maps API.<br \/>\n&nbsp;<br \/>\nIn this post I will cover:<\/p>\n<ol>\n<li><a href=\"#start\">Getting started with HTML5 Geolocation API.<\/a><\/li>\n<li><a href=\"#gmap1\">Integrating Google map to show current location.<\/a><\/li>\n<li><a href=\"#gmap2\">Enhancing to show nearby places on Google map.<\/a><\/li>\n<\/ol>\n<p>[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<h2><a name=\"start\"><\/a>Getting started with HTML5 Geolocation API<\/h2>\n<p>The Geolocation API enables the browser to identify the location of the user using various mechanisms like IP Address, GPS, Cellular networks depending on the device being used by the user. The location is identified as a pair of latitude and longitude values. Lets go ahead and create a simple html page and a javascript file to get the user location:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;meta charset='utf-8'&gt;\r\n    &lt;title&gt;Where am I?&lt;\/title&gt;\r\n    &lt;script src='myLoc.js'&gt;&lt;\/script&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;!-- The location will be updated in the below div --&gt;\r\n    &lt;div id='location'&gt;\r\n      Your location will go here.\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>And the javascript code which updates the above html with the user location is:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/myLoc.js\r\nwindow.onload = getMyLocation;\r\n\r\nfunction getMyLocation() {\r\n  if (navigator.geolocation) {\r\n    navigator.geolocation.getCurrentPosition(displayLocation);\r\n  } else {\r\n    alert('Oops, no geolocation support');\r\n  }\r\n}\r\n\r\n\/\/This function is inokved asynchronously by the HTML5 geolocation API.\r\nfunction displayLocation(position) {\r\n\r\n  \/\/The latitude and longitude values obtained from HTML 5 API.\r\n  var latitude = position.coords.latitude;\r\n  var longitude = position.coords.longitude;\r\n\r\n  \/\/Setting the latitude and longitude values in the div.\r\n  var div = document.getElementById('location');\r\n  div.innerHTML = 'You are at Latitude: ' + latitude + ', Longitude: ' + longitude;\r\n}<\/pre>\n<p>In the above javascript code the <code>navigator<\/code> object\u2019s <code>geolocation<\/code> property is used to obtain the location of the user. If the browser supports the HTML5 Geolocation API then it will ask confirmation from the user about accessing the user\u2019s location. Once the location has been identified it asynchronously invokes the callback <code>displayLocation<\/code> registered with the Geolocation API. The callback does nothing special other than updating the html with the latitude and longitude values.<\/p>\n<h2><a name=\"gmap1\"><\/a>Integrating Google map to show current location<\/h2>\n<p>To integrate the Google Map, one should start with the <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/tutorial\">Getting started<\/a> document of Google Map API which shows how to get a Google API Key and also some sample example to start using Google Maps API. One would have to do the following to mark the current location on the Google map:<\/p>\n<ol>\n<ol>\n<li>Create an <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#LatLng\" target=\"_blank\">LatLng<\/a> object using the latitude and longitude values obtained from the geolocation API<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/Creating a new object for using latitude and longitude values with Google map.\r\nvar latLng = new google.maps.LatLng(latitude, longitude);<\/pre>\n<ol>\n<ol>\n<li>Create a <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#MapOptions\" target=\"_blank\">MapOptions<\/a> object.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/Setting up the map options like zoom level, map type.\r\nvar mapOptions = {\r\n  center: latLng,\r\n  zoom: 18,\r\n  mapTypeId: google.maps.MapTypeId.ROADMAP\r\n};<\/pre>\n<ol>\n<ol>\n<li>Create a <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#Map\" target=\"_blank\">Map<\/a> object and pass the html element (in our case <code>div<\/code> tag) to embed the map and MapOptions object created in the step above.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/Creating the Map instance and assigning the HTML div element to render it in.\r\nvar map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);<\/pre>\n<ol>\n<ol>\n<li>Create a <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#MarkerOptions\" target=\"_blank\">MarkerOptions<\/a> object indicating the location to be marked on the map<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var markerOptions = {\r\n  position: latLng,\r\n  map: map,\r\n  animation: google.maps.Animation.DROP,\r\n  clickable: true\r\n}<\/pre>\n<ol>\n<ol>\n<li>Create a <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#Marker\" target=\"_blank\">Marker<\/a> object and provide it the MarkerOptions object and the Map object created in the steps above. This Marker object uses the MarkerOptions object to get the location information and then the Map object to mark the location.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/Setting up the marker object to mark the location on the map canvas.\r\nvar marker = new google.maps.Marker(markerOptions);<\/pre>\n<ol>\n<li>Additionally lets add an note window which would show some thing about the place when the user clicks on the location. This is achieved by creating an InfoWindowOptions object and using it to create an InfoWindow object. This note window should be opened when the user clicks on the marker which can be done by adding an event listener for <code>click<\/code> event.<\/li>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var infoWindowOptions = {\r\n  content: content,\r\n  position: latLng\r\n};\r\n\r\nvar infoWindow = new google.maps.InfoWindow(infoWindowOptions);\r\n\r\ngoogle.maps.event.addListener(marker, 'click', function() {\r\n  infoWindow.open(map);\r\n});<\/pre>\n<p>The complete code which shows the location on the Google map is given below:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;!-- index.html --&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;meta charset='utf-8'&gt;\r\n    &lt;title&gt;Where am I?&lt;\/title&gt;\r\n    &lt;script type='text\/javascript' src='https:\/\/maps.googleapis.com\/maps\/api\/js?sensor=true'&gt;&lt;\/script&gt;\r\n    &lt;script src='myLoc.js'&gt;&lt;\/script&gt;\r\n    &lt;style type='text\/css'&gt;\r\n      html { height: 100% }\r\n      body { height: 100%; margin: 0; padding: 0 }\r\n      #map-canvas { height: 100% }\r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id='location'&gt;\r\n      Your location will go here.\r\n    &lt;\/div&gt;\r\n    &lt;div id='map-canvas'&gt;\r\n      Google Map will go here!.\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>The javascript code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\/\/myLoc.js\r\nwindow.onload = getMyLocation;\r\n\/\/Note that map has been globally declared.\r\nvar map;\r\nfunction getMyLocation() {\r\n  if (navigator.geolocation) {\r\n    navigator.geolocation.getCurrentPosition(displayLocation);\r\n  } else {\r\n    alert('Oops, no geolocation support');\r\n  }\r\n}\r\n\r\n\/\/This function is inokved asynchronously by the HTML5 geolocation API.\r\nfunction displayLocation(position) {\r\n  \/\/The latitude and longitude values obtained from HTML 5 API.\r\n  var latitude = position.coords.latitude;\r\n  var longitude = position.coords.longitude;\r\n\r\n  \/\/Creating a new object for using latitude and longitude values with Google map.\r\n  var latLng = new google.maps.LatLng(latitude, longitude);\r\n\r\n  showMap(latLng);\r\n  createMarker(latLng);\r\n\r\n  \/\/Also setting the latitude and longitude values in another div.\r\n  var div = document.getElementById('location');\r\n  div.innerHTML = 'You are at Latitude: ' + latitude + ', Longitude: ' + longitude;\r\n}\r\n\r\nfunction showMap(latLng) {\r\n  \/\/Setting up the map options like zoom level, map type.\r\n  var mapOptions = {\r\n    center: latLng,\r\n    zoom: 18,\r\n    mapTypeId: google.maps.MapTypeId.ROADMAP\r\n  };\r\n\r\n  \/\/Creating the Map instance and assigning the HTML div element to render it in.\r\n  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);\r\n}\r\nfunction createMarker(latLng) {\r\n  \/\/Setting up the marker object to mark the location on the map canvas.\r\n  var markerOptions = {\r\n    position: latLng,\r\n    map: map,\r\n    animation: google.maps.Animation.DROP,\r\n    clickable: true\r\n  }\r\n  var marker = new google.maps.Marker(markerOptions);\r\n\r\n  var content = 'You are here: ' + latLng.lat() + ', ' + latLng.lng();\r\n  addInfoWindow(marker, latLng, content);\r\n\r\n}\r\n\r\nfunction addInfoWindow(marker, latLng, content) {\r\n  var infoWindowOptions = {\r\n    content: content,\r\n    position: latLng\r\n  };\r\n\r\n  var infoWindow = new google.maps.InfoWindow(infoWindowOptions);\r\n\r\n  google.maps.event.addListener(marker, 'click', function() {\r\n    infoWindow.open(map);\r\n  });\r\n}<\/pre>\n<h2><a name=\"gmap2\"><\/a>Enhancing to show nearby places on Google map<\/h2>\n<p>Now lets make use of the Places library and mark the nearby eatouts on the map. This involves the following steps:<\/p>\n<ol>\n<ol>\n<li>Create an instance of <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#PlacesService\" target=\"_blank\">PlacesService<\/a> using the Map object created previously.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var nearByService = new google.maps.places.PlacesService(map);<\/pre>\n<ol>\n<ol>\n<li>Create a <a href=\"https:\/\/developers.google.com\/maps\/documentation\/javascript\/reference#PlaceSearchRequest\" target=\"_blank\">PlacesSearchRequest<\/a> object to hold the information related to searching the places.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">var request = {\r\n  location: latLng,\r\n  radius: 1000,\r\n  types: &#x5B;'food', 'bakery', 'cafe',\r\n          'grocery_or_supermarket',\r\n          'meal_delivery','restaurant',\r\n          'meal_takeaway',\r\n          'shopping_mall']\r\n};<\/pre>\n<ol>\n<ol>\n<li>Create a callback method which will be invoked on obtaining the places result. This callback method will be provided with the results and the result status.<\/li>\n<\/ol>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">function handleNearBySearchResults(results, status) {\r\n  if (status == google.maps.places.PlacesServiceStatus.OK) {\r\n    for (var i = 0; i &lt; results.length; i++) {\r\n      var place = results&#x5B;i];\r\n      createMarker(place.geometry.location, place);\r\n    }\r\n  }\r\n}<\/pre>\n<ol>\n<li>Register the callback with the PlacesService object and also provide the PlacesSearchRequest object created above.<\/li>\n<\/ol>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">nearByService.nearbySearch(request, handleNearBySearchResults);<\/pre>\n<p>Lets look at the complete code which identifies the location, marks it on the Google map and also marks nearby eat outs on the map.<br \/>\nThe html for this is:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;meta charset='utf-8'&gt;\r\n    &lt;title&gt;Where am I?&lt;\/title&gt;\r\n    &lt;script type='text\/javascript'\r\n    src='https:\/\/maps.googleapis.com\/maps\/api\/js?sensor=true&amp;libraries=places,weather'&gt;&lt;\/script&gt;\r\n    &lt;script src='myLoc.js'&gt;&lt;\/script&gt;\r\n    &lt;style type='text\/css'&gt;\r\n      html { height: 100% }\r\n      body { height: 100%; margin: 0; padding: 0 }\r\n      #map-canvas { height: 100% }\r\n    &lt;\/style&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id='location'&gt;\r\n      Your location will go here.\r\n    &lt;\/div&gt;\r\n    &lt;div id='map-canvas'&gt;\r\n      Google Map will go here!.\r\n    &lt;\/div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>The javascript code for this is:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">window.onload = getMyLocation;\r\n\r\nvar map;\r\nfunction getMyLocation() {\r\n  if (navigator.geolocation) {\r\n    navigator.geolocation.getCurrentPosition(displayLocation);\r\n  } else {\r\n    alert('Oops, no geolocation support');\r\n  }\r\n}\r\n\r\n\/\/This function is inokved asynchronously by the HTML5 geolocation API.\r\nfunction displayLocation(position) {\r\n  \/\/The latitude and longitude values obtained from HTML 5 API.\r\n  var latitude = position.coords.latitude;\r\n  var longitude = position.coords.longitude;\r\n\r\n  \/\/Creating a new object for using latitude and longitude values with Google map.\r\n  var latLng = new google.maps.LatLng(latitude, longitude);\r\n\r\n  showMap(latLng);\r\n\r\n  addNearByPlaces(latLng);\r\n  createMarker(latLng);\r\n\r\n  \/\/Also setting the latitude and longitude values in another div.\r\n  var div = document.getElementById('location');\r\n  div.innerHTML = 'You are at Latitude: ' + latitude + ', Longitude: ' + longitude;\r\n}\r\n\r\nfunction showMap(latLng) {\r\n  \/\/Setting up the map options like zoom level, map type.\r\n  var mapOptions = {\r\n    center: latLng,\r\n    zoom: 18,\r\n    mapTypeId: google.maps.MapTypeId.ROADMAP\r\n  };\r\n\r\n  \/\/Creating the Map instance and assigning the HTML div element to render it in.\r\n  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);\r\n}\r\n\r\nfunction addNearByPlaces(latLng) {\r\n\r\n  var nearByService = new google.maps.places.PlacesService(map);\r\n\r\n  var request = {\r\n    location: latLng,\r\n    radius: 1000,\r\n    types: &#x5B;'food', 'bakery', 'cafe', 'grocery_or_supermarket', 'meal_delivery','restaurant', 'meal_takeaway', 'shopping_mall']\r\n  };\r\n\r\n  nearByService.nearbySearch(request, handleNearBySearchResults);\r\n}\r\n\r\nfunction handleNearBySearchResults(results, status) {\r\n  if (status == google.maps.places.PlacesServiceStatus.OK) {\r\n    for (var i = 0; i &lt; results.length; i++) {\r\n      var place = results&#x5B;i];\r\n      createMarker(place.geometry.location, place);\r\n    }\r\n  }\r\n}\r\n\r\nfunction createMarker(latLng, placeResult) {\r\n  var markerOptions = {\r\n    position: latLng,\r\n    map: map,\r\n    animation: google.maps.Animation.DROP,\r\n    clickable: true\r\n  }\r\n  \/\/Setting up the marker object to mark the location on the map canvas.\r\n  var marker = new google.maps.Marker(markerOptions);\r\n\r\n  if (placeResult) {\r\n    var content = placeResult.name+'&lt;br\/&gt;'+placeResult.vicinity+'&lt;br\/&gt;'+placeResult.types;\r\n    addInfoWindow(marker, latLng, content);\r\n  }\r\n  else {\r\n    var content = 'You are here: ' + latLng.lat() + ', ' + latLng.lng();\r\n    addInfoWindow(marker, latLng, content);\r\n  }\r\n\r\n}\r\n\r\nfunction addInfoWindow(marker, latLng, content) {\r\n  var infoWindowOptions = {\r\n    content: content,\r\n    position: latLng\r\n  };\r\n\r\n  var infoWindow = new google.maps.InfoWindow(infoWindowOptions);\r\n\r\n  google.maps.event.addListener(marker, 'click', function() {\r\n    infoWindow.open(map);\r\n  });\r\n}<\/pre>\n<p>Some of the recommended books:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.flipkart.com\/html5-up-running\/p\/itmczzj4kqbtbhns?pid=9789350230824&amp;affid=INMohamblo\">HTML5 : Up and Running<\/a><\/li>\n<li><a href=\"http:\/\/www.flipkart.com\/head-first-html5-programming-1st\/p\/itmd45dxk5m6sg7k?pid=9789350235324&amp;affid=INMohamblo\">Head First HTML5 Programming 1st Edition<\/a><\/li>\n<li><a href=\"http:\/\/www.flipkart.com\/html5-geolocation\/p\/itmdf86cen37mxhk?pid=9789350234174&amp;affid=INMohamblo\">HTML5 Geolocation<\/a><\/li>\n<\/ul>\n<p>You can access this sample application live <a href=\"http:\/\/sanaulla.info\/html5\/geolocation\/\">here<\/a>.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/blog.sanaulla.info\/2013\/08\/16\/html5-geolocation-api-with-goolge-maps\/\">HTML5 Geolocation API with Goolge Maps<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/wcg\/\">WCG partner<\/a> Mohamed Sanaulla at the <a href=\"http:\/\/blog.sanaulla.info\">Experiences Unlimited<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the Google Maps with HTML5 geolocation API. It was an interesting example and I went a step further and enhanced the example to show some eat outs around the &hellip;<\/p>\n","protected":false},"author":3,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[30,31],"class_list":["post-1097","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5","tag-geolocation","tag-google-maps"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-31T13:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T13:41:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mohamed Sanaulla\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohamed Sanaulla\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\"},\"author\":{\"name\":\"Mohamed Sanaulla\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/25d8251ab46cf28d12fa1ef1d02d22d1\"},\"headline\":\"HTML5 Geolocation API with Google Maps\",\"datePublished\":\"2014-10-31T13:23:56+00:00\",\"dateModified\":\"2017-12-19T13:41:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\"},\"wordCount\":1789,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"keywords\":[\"Geolocation\",\"Google Maps\"],\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\",\"name\":\"HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2014-10-31T13:23:56+00:00\",\"dateModified\":\"2017-12-19T13:41:03+00:00\",\"description\":\"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 Geolocation API with Google Maps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/25d8251ab46cf28d12fa1ef1d02d22d1\",\"name\":\"Mohamed Sanaulla\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/64131fe9e9472b8852abf595cbbf3a8a2a5e86569fa1349eed92b2a32f9104c1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/64131fe9e9472b8852abf595cbbf3a8a2a5e86569fa1349eed92b2a32f9104c1?s=96&d=mm&r=g\",\"caption\":\"Mohamed Sanaulla\"},\"sameAs\":[\"http:\/\/blog.sanaulla.info\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/mohamed-sanaulla\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026","description":"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026","og_description":"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2014-10-31T13:23:56+00:00","article_modified_time":"2017-12-19T13:41:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Mohamed Sanaulla","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Mohamed Sanaulla","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/"},"author":{"name":"Mohamed Sanaulla","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/25d8251ab46cf28d12fa1ef1d02d22d1"},"headline":"HTML5 Geolocation API with Google Maps","datePublished":"2014-10-31T13:23:56+00:00","dateModified":"2017-12-19T13:41:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/"},"wordCount":1789,"commentCount":4,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","keywords":["Geolocation","Google Maps"],"articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/","name":"HTML5 Geolocation API with Google Maps - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2014-10-31T13:23:56+00:00","dateModified":"2017-12-19T13:41:03+00:00","description":"I have been reading Head First HTML5 and read about the Geolocation support in HTML5 and also went through the example they have shared about using the","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-geolocation-api-with-google-maps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 Geolocation API with Google Maps"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/25d8251ab46cf28d12fa1ef1d02d22d1","name":"Mohamed Sanaulla","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/64131fe9e9472b8852abf595cbbf3a8a2a5e86569fa1349eed92b2a32f9104c1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/64131fe9e9472b8852abf595cbbf3a8a2a5e86569fa1349eed92b2a32f9104c1?s=96&d=mm&r=g","caption":"Mohamed Sanaulla"},"sameAs":["http:\/\/blog.sanaulla.info"],"url":"https:\/\/www.webcodegeeks.com\/author\/mohamed-sanaulla\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=1097"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1097\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=1097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=1097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=1097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}