Click here to Skip to main content
14,428,997 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am trying to bind multiple lat long on google map. But it showing anything neither it gives any error

What I have tried:

function getUrlVars() {
   var vars = [], hash;
   var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
   for (var i = 0; i < hashes.length; i++) {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
   }
   return vars;
}
var map;
function initialize() {
   var mapProp = {
      center: new google.maps.LatLng(38, -78),
      zoom: 6,
      mapTypeId: google.maps.MapTypeId.ROADMAP
   };
   map = new google.maps.Map(document.getElementById('map_canvas'), mapProp);
};
$(document).ready(function () {
   var source = {};
   var otp = getUrlVars()["otp"];
   try{
      $.ajax({
         url: 'ShowOnMap.aspx/GetMapData',
         data: JSON.stringify({ ulb: otp }),
         dataType: "json",
         type: "POST",
         contentType: "application/json; charset=utf-8",
         success: function (data) {
         },
         success: function (data) {
            debugger;
            $.each(data, function () {

               var myLatLng = new google.maps.LatLng(this.h_lat, this.h_long);
               var contentString = '<span style="color:green;font-size:10pt;">Hospital Name:' + this.h_name + '</span>';
               var infowindow = new google.maps.InfoWindow();
               var marker = new google.maps.Marker({
                  position: myLatLng,
                  map: map
                                        
               });
               google.maps.event.addListener(marker, 'click', function () {
                  infowindow.setContent(contentString);
                  infowindow.open(map, this);
               });


            });
         },
         error: function (response) {
            alert('error');
         },
         failure: function (response) {
            alert('failed');
         }
      });
   }                   
   catch (err) {
      alert(err.message);
   }
});
Posted
Updated 7-Sep-19 10:36am
v2
Comments
Udhay Titus P 11-Sep-19 0:26am
   
check this fiddle it will helps you http://jsfiddle.net/Ankit47/uj5xdcx8/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100