Quick Google Maps API / Javascipt question

Discussion in 'Programming & Software Development' started by PacketStorm4, May 9, 2014.

  1. PacketStorm4

    PacketStorm4 Member

    Joined:
    Dec 13, 2007
    Messages:
    229
    Location:
    Phos Vegas!
    Evening,

    Recently followed Google's guide on creating custom maps using PHP and SQL.

    I's stuck at one section where I am trying to add some HTML to the info box.


    Code:
    function load() {
          var map = new google.maps.Map(document.getElementById("map"), {
            center: new google.maps.LatLng(-25.6145, 136.3418),
            zoom: 4,
            mapTypeId: 'roadmap'
          });
          var infoWindow = new google.maps.InfoWindow;
    
          // Change this depending on the name of your PHP file
          downloadUrl("phpsqlajax_genxml22.php", function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
              var name = markers[i].getAttribute("name");
              var address = markers[i].getAttribute("address");
              var type = markers[i].getAttribute("type");
    		  var type = markers[i].getAttribute("html");
              var point = new google.maps.LatLng(
                  parseFloat(markers[i].getAttribute("lat")),
                  parseFloat(markers[i].getAttribute("lng")));
              var html = "<b>" + name + "</b> <br/>" + address;
              var icon = customIcons[type] || {};
              var marker = new google.maps.Marker({
                map: map,
                position: point,
                icon: icon.icon
              });
              bindInfoWindow(marker, map, infoWindow, html);
    This is the line that will need modification as it is calling our variables:
    Top Line, Bold Heading
    Second Line, 'address' that is a hyperlink
    Code:
    var html = "<b>" + name + "</b> <br/>" + address;
    How am I able add a URL with a variable in there?
    I tried the following example:
    Code:
    var html = "<b>" + name + "</b> <br/>""<a href="http://test.com/+ address+"> + address </a>;
    What am I doing wrong here?
     
  2. OP
    OP
    PacketStorm4

    PacketStorm4 Member

    Joined:
    Dec 13, 2007
    Messages:
    229
    Location:
    Phos Vegas!
    got it!

    Code:
    	var html = '<b>' + name + '</b><br/><a href="http://test.com/' + address + '">' + address + '</a>';
     

Share This Page

Advertisement: