jQuery provides GMaps Plugin which helps programmers to use Google Maps in a variety of ways. You have to download the required files in the working folder so that the programmer can include them in the head section of the HTML structure page as implemented in the following programs.
jQuery GMaps Plugin download link: https://hpneo.dev/gmaps/
In the following examples, we are using a valid existing location's latitude and longitude which can be obtained by entering a location address in the input control box from the below link. Please make a note of the latitude and longitude of the user input address for further proceeding in the code.
https://www.latlong.net/
Example 1: The following example demonstrates the basic call of the GMaps plugin based on latitude and longitude values to show the location in the map.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery GMaps Plugin</title>
<script type="text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript"
src=
"http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript"
src="gmaps.js">
</script>
<link rel="stylesheet"
href=
"http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
<link rel="stylesheet"
type="text/css"
href="examples.css" />
<style>
body {
text-align: center;
}
</style>
<script type="text/javascript">
let map;
$(document).ready(function () {
map = new GMaps({
el: "#map",
lat: 21.164904,
lng: 81.324297,
zoomControl: true,
zoomControlOpt: {
style: "SMALL",
position: "BOTTOM_LEFT",
},
panControl: true,
streetViewControl: true,
mapTypeControl: true,
});
});
</script>
</head>
<body>
<h1 style="color: green;">
GeeksForGeeks
</h1>
<b>jQuery GMaps Plugin</b>
<div class="row">
<div class="span11">
<div id="map"></div>
</div>
</div>
</body>
</html>
Output :
Example 2: The following program uses the GMap plugin to draw circle around the input location.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery GMaps Plugin</title>
<script type="text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript"
src=
"http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript"
src="gmaps.js">
</script>
<link rel="stylesheet"
href=
"http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
<link rel="stylesheet"
type="text/css"
href="examples.css" />
<style>
body {
text-align: center;
}
</style>
<script type="text/javascript">
let map;
$(document).ready(function () {
map = new GMaps({
el: "#map",
lat: 17.4574683,
lng: 78.2822645,
});
let latitude = 17.4574683;
let longitude = 78.2822645;
circle = map.drawCircle({
lat: latitude,
lng: longitude,
radius: 451,
strokeColor: "#33FFAF",
strokeOpacity: 1,
strokeWeight: 4,
fillColor: "#33FFAF",
fillOpacity: 0.5,
});
for (let i in paths) {
bounds.push(paths[i]);
}
let arrayVar = [];
for (let i in bounds) {
latitudeLongitude =
new google.maps.LatLng(bounds[i][0], bounds[i][1]);
arrayVar.push(latitudeLongitude);
}
for (let i in paths) {
latitudeLongitude =
new google.maps.LatLng(paths[i][0], paths[i][1]);
arrayVar.push(latitudeLongitude);
}
map.fitLatLngBounds(arrayVar);
});
</script>
</head>
<body>
<h1 style="color: green;">
GeeksForGeeks
</h1>
<b>
Draw circle using GMaps Plugin
</b>
<div class="row">
<div class="span11">
<div id="map"></div>
</div>
</div>
</body>
</html>
Output :
Example 3: The following program demonstrates the event handling feature of the plugin. It shows messages on click and drag events.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery GMaps Plugin Event handling</title>
<script type="text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript"
src=
"http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript"
src="gmaps.js">
</script>
<link rel="stylesheet"
href=
"http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
<link rel="stylesheet"
type="text/css"
href="examples.css" />
<style>
body {
text-align: center;
}
.eventClass {
width: 90%;
text-align: center;
font-weight: bold;
padding: 10px;
box-sizing: content-box;
}
</style>
<script type="text/javascript">
let map;
$(document).ready(function () {
map = new GMaps({
el: "#map",
zoom: 15,
lat: 17.4574683,
lng: 78.2822645,
click: function (e) {
let info = "Click event occurred!";
$("#ClickEventDivID").text(info);
},
dragend: function (e) {
let info = "User dragged a location !";
$("#DragEventDivID").text(info);
},
});
});
</script>
</head>
<body>
<h1 style="color: green;">
GeeksForGeeks
</h1>
<b>
jQuery GMaps Plugin Event handling
</b>
<div class="row">
<div class="span11">
<div id="map"></div>
</div>
</div>
<br />
<br />
<div id="ClickEventDivID"
class="eventClass">
</div>
<div id="DragEventDivID"
class="eventClass">
</div>
</body>
</html>
Output :
Example 4: The following example demonstrates OpenStreetMap map type of the GMap plugin.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery GMaps Plugins Map Types</title>
<script type="text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">
</script>
<script type="text/javascript"
src=
"http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript"
src="gmaps.js">
</script>
<link rel="stylesheet"
href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
<link rel="stylesheet"
type="text/css"
href="examples.css" />
<style>
body {
text-align: center;
}
</style>
<script type="text/javascript">
let map;
$(document).ready(function () {
map = new GMaps({
el: "#map",
lat: 17.47514,
lng: 78.3003,
mapTypeControlOptions: {
mapTypeIds: ["hybrid", "roadmap", "satellite",
"terrain", "osm", "cloudmade"],
},
});
map.addMapType("osm", {
getTileUrl: function (coord, zoom) {
return "http://tile.openstreetmap.org/"
+ zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
name: "OpenStreetMap",
maxZoom: 15,
});
map.setMapTypeId("osm");
});
</script>
</head>
<body>
<h1 style="color: green;">
GeeksForGeeks
</h1>
<b>
jQuery GMaps Plugin Open Street Map
</b>
<div class="row">
<div class="span11">
<div id="map"></div>
</div>
</div>
</body>
</html>
Output :
Example 5: The following example demonstrates adding layers to the location in map which is shown in the output image.
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jQuery GMaps Layers Maps</title>
<script src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script src=
"http://maps.google.com/maps/api/js?sensor=true&libraries=weather">
</script>
<script src="gmaps.js">
</script>
<link rel="stylesheet"
href=
"http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css" />
<link rel="stylesheet"
type="text/css"
href="examples.css" />
<style>
body {
text-align: center;
}
</style>
<script type="text/javascript">
let map;
$(function () {
map = new GMaps({
el: "#map",
lat: 17.4574683,
lng: 78.2822645,
zoom: 3,
});
map.addLayer("weather", {
clickable: true,
});
map.addLayer("traffic");
});
</script>
</head>
<body>
<h1 style="color: green">
GeeksForGeeks
</h1>
<b>
jQuery GMaps Adding layers Feature
</b>
<div class="row">
<div class="span11">
<div id="map"></div>
</div>
</div>
</body>
</html>
Output :
There are many more variety of ways to make use of google maps using GMap plugin. The programmer can make use of all these depending on the application's requirement.
Similar Reads
jQuery Page Piling Plugin jQuery pagePiling.js plug-in is a rich feature available for programmers for piling more than one layout section, one over the other, and accessing each page by URL or mouse scrolling or side bullets navigation. This feature provides all type of smooth vertical, horizontal, and side navigations to t
5 min read
jQuery | Flickerplate Plugin jQuery provides Flickerplate plugin that helps our programmers to create sliders for websites that can cycle through a list of background images along with dot navigation feature and animated arrows. The plugin consists of many more libraries that are responsible for touch detections and events such
5 min read
jQuery Multiscroll Plugin jQuery provides multiscroll.js plugin which helps programmers to create split web pages along with divided multiple vertical scrolling panels.Note: Please download the jQuery multiscroll plugin to your working folder and include the required files in the head section of your code as shown below. Dow
3 min read
jQuery RowGrid Plugin jQuery provides a very simple, user-friendly and responsive rowGrid plugin that helps programmers to display images in a straight row. It is very lightweighted and supports infinite scrolling feature. Real examples of rowGrid are Google+ images or Google image search that appears in a straight row g
4 min read
jQuery Alertify Plugin jQuery framework provides alertify.js plugin that provides pre-designed customizable notification system along with interactive browser dialogs. This extensible and themeable plugin is very useful for developers providing an optimized version of alert messages with stacking up to feature. This small
5 min read
jQuery Image ProgressBars Plugin In this article, we will learn how to implement image ProgressBar feature using the jQuery Image ProgressBar plugin. Note: Please download the jQuery Image ProgressBar plugin in the working folder and include the required files in the head section of your HTML code. <link href=âprogressbar.cssâ r
2 min read
jQuery DrawSVG Plugin SVG or Scalar Vector Graphics is Extended Markup Language-based graphics supporting 2 dimensional animations of images enhancing interactiveness. The specifications of SVG are open standards by World Wide Web Consortium defined in XML text files. These files can be changed or created with any drawin
4 min read
jQuery Tagsort Plugin jQuery provides Tagsort plugin that is used for displaying tags or filter elements based on different tags in a DOM. The plugin takes data-attributes of HTML page structure and dynamically creates user-friendly tags used for filtering elements. The filtration of elements are done in many ways that a
9 min read
jQuery Logos Distort Plugin The jQuery provides LogosDistort plugin which helps in creating or animating a parallax environment for 3D scenes in the user browser. It uses full-page matrix3D perspective logos distortions for transforming base on mouse movement. You have to download the required files in the working folder so th
4 min read
jQuery Filer Plugin jQuery provides a quick jQuery Filer uploader plugin for easy implementation of uploading the files. It provides features like instant uploading of files, file append, file removal, multiple selections, drag and drop support along with other file validations.Download the required files to include it
2 min read