WPDIR
Everything and everyone WordPress

Embed Google Maps that centers on business address??

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #872 Reply
    Cheryl
    Guest

    Tried to auto-generate a Google Map for hundreds of sites using a WordPress theme that plugs in the business address and name, but the iframe is unpredictable and sometimes works and sometimes doesn’t work accurately.

    Some devs have said using latitude and longitude works better, also removes some of the annoying features in the iframe, but it would take me forever to find the GPS location for every business. Solutions??

    #873 Reply
    Betty
    Guest
    #874 Reply
    Marilyn
    Guest

    The iframes suck balls for Google Maps, you have to use the JS API with geocoder variable.

    That will force convert address to GPS before rendering the map.

    #875 Reply
    Lawrence
    Guest

    Here is a nice example:

    https://gist.github.com/mahedi2014/a71e1bbcbd69d4a9d491b0f289894d2d

    <div id="map" style="width:70%;height:500px;"></div>
    <h5>Tolarbag Mosque Road, Dhaka, Dhaka Division, Bangladesh</h5>
     
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script>
    var geocoder = new google.maps.Geocoder(); // initialize google map object
    var address = "Tolarbag Mosque Road, Dhaka, Dhaka Division, Bangladesh";
    geocoder.geocode( { 'address': address}, function(results, status) {
     
    if (status == google.maps.GeocoderStatus.OK) {
        var latitude = results[0].geometry.location.lat();
    var longitude = results[0].geometry.location.lng();
    var myCenter=new google.maps.LatLng(latitude,longitude);
           function initialize()
    {
    var mapProp = {
      center:myCenter,
      zoom:7,
      mapTypeId:google.maps.MapTypeId.ROADMAP
      };
     
    var map=new google.maps.Map(document.getElementById("map"),mapProp);
     
    var marker=new google.maps.Marker({
      position:myCenter,
      });
     
    marker.setMap(map);
    }
     
    google.maps.event.addDomListener(window, 'load', initialize); 
        } 
    }); 
    </script>
    #890 Reply
    Daniel
    Guest

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Embed Google Maps that centers on business address??