Introduction

You can specify an image instead of the default marker in Google Maps.

Description

Follow my Google Maps Part-1 ,Part-2 and Part-3 blogs before you go through the Part-4.

Steps

Create a Controller action method named "Icon" in the same Controller class named "HomeController.cs".
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. namespace SatyaGoogleMapBootstrapMVC.Controllers
  7. {
  8. public class HomeController : Controller
  9. {
  10. //
  11. // GET: /Home/
  12. public ActionResult Index()
  13. {
  14. return View();
  15. }
  16. public ActionResult Details()
  17. {
  18. return View();
  19. }
  20. public ActionResult Animate()
  21. {
  22. return View();
  23. }
  24. public ActionResult Icon()
  25. {
  26. return View();
  27. }
  28. }
  29. }
Then, create a View named "Icon.cshtml".
  1. @{
  2. ViewBag.Title = "Satyaprakash Google Map Icon";
  3. }
  4. <title>@ViewBag.Title</title>
  5. <h2 style="background-color: Yellow;color: Blue; text-align: center; font-style: oblique">Satyaprakash's Google Map Icon Using MVC and BOOTSTRAP</h2>
  6. <fieldset>
  7. <legend style="font-family: Arial Black; color: blue; font-size: large;">Check Google Map Icon</legend>
  8. <meta charset="utf-8">
  9. <meta name="viewport" content="width=device-width, initial-scale=1">
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  11. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  12. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  13. <div id="map" style="width:100%;height:500px"></div>
  14. <script>
  15. function myMap() {
  16. var mapCanvas = document.getElementById("map");
  17. var myCenter = new google.maps.LatLng(20.296100, 85.824500);
  18. var mapOptions = { center: myCenter, zoom: 12 };
  19. var map = new google.maps.Map(mapCanvas, mapOptions);
  20. var marker = new google.maps.Marker({
  21. position: myCenter,
  22. icon: "Flag.png"
  23. });
  24. marker.setMap(map);
  25. }
  26. </script>
  27. <script src="https://maps.googleapis.com/maps/api/js?key=put_your_key&callback=myMap"></script>
  28. </fieldset>
  29. <footer>
  30. <p style="background-color: Yellow; font-weight: bold; color:blue; text-align: center; font-style: oblique">© @DateTime.Now.ToLocalTime()</p> @*Add Date Time*@
  31. </footer>
Here, I set my own image file instead of default Google Maps marker.
  1. var marker = new google.maps.Marker({
  2. position: myCenter,
  3. icon: "Flag.png"
  4. });
OUTPUT

Url: http://localhost:57237/Home/Icon
Desktop View


Mobile View



Summary
  1. Use image instead of marker In Google Maps.
  2. Implementing Mvc and Bootstrap.