Google Maps - Polygon With Animated Marker Using Bootstrap In ASP.NET MVC - Part Six

Introduction

A polygon consists of a series of coordinates in an ordered sequence. However, polygons are designed to define place coordinates within a closed loop. Polygons are made of straight lines.

Follow my Google Maps part 1- 5 blogs before you go through to part 6.

Description


A polygon supports the following properties.
  1. path - specifies several LatLng coordinates for the line.
  2. strokeColor - specifies a hexadecimal color for the line.
  3. strokeOpacity - specifies the opacity of the line.
  4. strokeWeight - specifies the weight of the line's stroke in pixels.
  5. fillColor - specifies a hexadecimal color for the area within the enclosed region.
  6. fillOpacity - specifies the opacity of the fill color.
  7. editable - defines whether the line is editable by users.
Steps

Create a Controller class file.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace SatyaGoogleMapBootstrapMVC.Controllers  
  8. {  
  9.     public class HomeController : Controller  
  10.     {  
  11.         //  
  12.         // GET: /Home/  
  13.   
  14.         public ActionResult Index()  
  15.         {  
  16.             return View();  
  17.         }  
  18.         public ActionResult Details()  
  19.         {  
  20.             return View();  
  21.         }  
  22.         public ActionResult Animate()  
  23.         {  
  24.             return View();  
  25.         }  
  26.         public ActionResult Icon()  
  27.         {  
  28.             return View();  
  29.         }  
  30.     }  

 Create a View file named "Icon.cshtml".
  1. @{  
  2.     ViewBag.Title = "Satyaprakash Google Map Polygon";  
  3. }  
  4.   
  5. <title>@ViewBag.Title</title>  
  6.   
  7. <h2 style="background-color: Yellow;color: Blue; text-align: center; font-style: oblique">Satyaprakash's Google Map Polygon Using MVC and BOOTSTRAP</h2>  
  8. <fieldset>  
  9.     <legend style="font-family: Arial Black; color: blue; font-size: large;">Check Area Occupied By 3 Cities Using Google Map Polygon</legend>  
  10.     <meta charset="utf-8">  
  11.     <meta name="viewport" content="width=device-width, initial-scale=1">  
  12.     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">  
  13.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  
  14.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  
  15.   
  16.     <div id="map" style="width:100%;height:500px"></div>  
  17.     <script>  
  18.         function myMap() {  
  19.             var Bhubaneswar = new google.maps.LatLng(20.296100, 85.824500);  
  20.             var Hyderabad = new google.maps.LatLng(17.3850, 78.4867);  
  21.             var Bangalore = new google.maps.LatLng(12.9716, 77.5946);  
  22.   
  23.             var mapCanvas = document.getElementById("map");  
  24.             var mapOptions = { center: Hyderabad, zoom: 6 };  
  25.             var map = new google.maps.Map(mapCanvas, mapOptions);  
  26.   
  27.             var flightPath = new google.maps.Polygon({  
  28.                 path: [Bhubaneswar, Hyderabad, Bangalore],  
  29.                 strokeColor: "Green",  
  30.                 strokeOpacity: 0.8,  
  31.                 strokeWeight: 2,  
  32.                 fillColor: "Yellow",  
  33.                 fillOpacity: 0.4  
  34.             });  
  35.   
  36.             var marker1 = new google.maps.Marker({  
  37.                 position: Bhubaneswar,  
  38.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  39.             });  
  40.             var marker2 = new google.maps.Marker({  
  41.                 position: Hyderabad,  
  42.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  43.             });  
  44.             var marker3 = new google.maps.Marker({  
  45.                 position: Bangalore,  
  46.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  47.             });  
  48.   
  49.             flightPath.setMap(map);  
  50.             marker1.setMap(map);  
  51.             marker2.setMap(map);  
  52.             marker3.setMap(map);  
  53.         }  
  54.     </script>  
  55.   
  56.     <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkVZYQFe4YYva_g5ulymGDt9EBoVjjZJ8&callback=myMap"></script>  
  57.   
  58. </fieldset>  
  59. <footer>  
  60.     <p style="background-color: Yellow; font-weight: bold; color:blue; text-align: center; font-style: oblique">© @DateTime.Now.ToLocalTime()</p> @*Add Date Time*@  
  61. </footer> 
 Here, I have mentioned three cities with their proper longitude and latitude details.
  1. var Bhubaneswar = new google.maps.LatLng(20.296100, 85.824500);  
  2. var Hyderabad = new google.maps.LatLng(17.3850, 78.4867);  
  3. var Bangalore = new google.maps.LatLng(12.9716, 77.5946); 
Then, I mentioned the polygon border color and fill color followed by opacity.
  1. var flightPath = new google.maps.Polygon({  
  2.                 path: [Bhubaneswar, Hyderabad, Bangalore],  
  3.                 strokeColor: "Green",  
  4.                 strokeOpacity: 0.8,  
  5.                 strokeWeight: 2,  
  6.                 fillColor: "Yellow",  
  7.                 fillOpacity: 0.4  
  8.             }); 
Finally, I put the animated marker for 3 different cities with polygon.
  1. var marker1 = new google.maps.Marker({  
  2.                 position: Bhubaneswar,  
  3.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  4.             });  
  5.             var marker2 = new google.maps.Marker({  
  6.                 position: Hyderabad,  
  7.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  8.             });  
  9.             var marker3 = new google.maps.Marker({  
  10.                 position: Bangalore,  
  11.                 animation: google.maps.Animation.BOUNCE //BOUNCE ,DROP , lo , no  
  12.             });   
OUTPUT

Desktop View
(with Satelite and Map View)
 
 
 
Mobile View (with Satelite and Map View)
 
 
 
 
 
 
 
 
 
Summary
 
In this blog, we learned the following.  
  1. What is Google Maps Polygon.
  2. How to implement it in MVC and Bootstrap.
  3. Purpose behind Google Maps Polygon.
  4. Using animated marker with Google Maps Polygon.
Ebook Download
View all
Learn
View all