Got more questions? Find advice on: SQL | XML | Regular Expressions | Windows
in Search
Welcome to AspAdvice Sign in | Join | Help

Adding Google Maps

Last post 01-04-2008, 5:41 PM by carlcamera. 5 replies.
Sort Posts: Previous Next
  •  01-04-2008, 1:00 PM 38184

    Adding Google Maps

    Starting a new thread from a side-discussion in this post

    Hey, how do you make it so the "info balloon" is already popped up when the map loads? I'd like to do that too. I tried, but it was the wee hours of the morning and I could not figure it out.

     

    I've started using map.openInfoWindowHtml recently and it's worked well for me.


    function googleload() {
    if (document.getElementById("map") == null) { return; }
    if (GBrowserIsCompatible()) {
    var map;
    var lat = "30.28453";
    var lng = "-97.823896";
    var mapctrlat = "30.28453";
    var mapctrlng = "-97.823896";
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(mapctrlat,mapctrlng), 15);
    // Create our "tiny" marker icon
    var icon = new GIcon();
    icon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
    icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    icon.iconSize = new GSize(12, 20);
    icon.shadowSize = new GSize(22, 20);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);
    var point = new GLatLng(lat,lng);
    map.openInfoWindowHtml(point,"<p><b>Bill Flood, Broker, Realtor</b><br />1101 South Capital of TX Hwy<br />Austin TX 78746</p>");
    map.addOverlay(new GMarker(point,icon));
    var mapstyle = document.getElementById('map');
    mapstyle.style.font = 'small arial';
    }
    }

    Sincerely,

    Carl
    -----
    vine type - content management with standards in mind - vinetype.com
    -----
    Filed under: ,
  •  01-04-2008, 1:32 PM 38190 in reply to 38184

    Re: Adding Google Maps

    One thing I've noticed. The code you're using turns the info balloon on by default, and the user can close it (click the X), but once they've closed it, they cannot reopen it by just clicking on the marker. They'd have to reload the page.

    The code I picked up and am currently using (also now shown on my blog at www.dougjoseph.net) allows the marker's info balloon to be opened and closed by clicking on the marker.

    Now if I just get the two combined. I want to have it on by default, and still be toggle-able by clicking on the marker.

    I have not really tried very hard yet. I may look into it now. Last night I was foggy brained at the wee hours of the morning.


    Sincerely,
    Doug Joseph
    Filed under: ,
  •  01-04-2008, 1:43 PM 38193 in reply to 38190

    Re: Adding Google Maps

    Well, mine comes back but you have to click the refresh button instead of the marker.  < grin >

     


    Sincerely,

    Carl
    -----
    vine type - content management with standards in mind - vinetype.com
    -----
    Filed under:
  •  01-04-2008, 1:53 PM 38194 in reply to 38190

    Re: Adding Google Maps

    Got it. Thanks for your help!!!!

    The combination of what you showed me, plus what I am using from the other site, gets what I want.

    The code I picked up and am using, allows for multiple markers on the map, so all the points and marker data chucks are stored in single vars as arrays. It was just a matter of catching the iteration through the array at the right point and then adding:

    map.openInfoWindowHtml(ps[i], ls[i]);

    Thanks again for your great help!!!!


    Sincerely,
    Doug Joseph
    Filed under: ,
  •  01-04-2008, 2:09 PM 38195 in reply to 38193

    Re: Adding Google Maps

    Here is the code with arrays for multiple markers. See it in action at: http://cac.us.com/map/

    This code currently works for me with using only one marker, and it has the marker's info balloon displayed by default, and it is toggle-able by clicking the marker. This var's point values: "i1.infoWindowAnchor = new GPoint(21, 80);"  are for half the width of the marker icon, and all of its height. The same is true of the i1.iconAnchor values.

     <script type="text/javascript">
     <!--
     //<![CDATA[
     
        function createMarker(p, l, i) {
      var marker = new GMarker(p, i);
     
      // Show this marker's index in the info window when it is clicked
       if (l != '') {
        GEvent.addListener(marker, "click", function() {
         marker.openInfoWindowHtml(l);
        });
       }
      return marker;
      }
     
     function reCenter(index) {
      map.panTo(ps[index], map.getZoom());
      mrs[index].openInfoWindowHtml(ls[index]);
     }
     
        function load() { 
      if (GBrowserIsCompatible()) {
       var i1 = new GIcon();
       i1.image = "http://cac.us.com/images/map/CAC-map-marker.png";
       i1.iconSize = new GSize(43, 80);
       i1.iconAnchor = new GPoint(20, 80);
       i1.shadow = "http://cac.us.com/images/map/CAC-map-marker-shadow.png";
       i1.shadowSize = new GSize(87, 80);
       i1.infoWindowAnchor = new GPoint(21, 80);
       
       var map = new GMap2(document.getElementById("map"));
      
       map.addControl(new GLargeMapControl());
       //map.addControl(new GMapTypeControl()); // this adds the "map/satellite/hybrid" choice
      
       map.setCenter(new GLatLng(39.2841, -80.3043), 12, G_NORMAL_MAP);
     
       var marker = 0;
     
       var mrs = new Array(1);
       var ps = new Array(new GLatLng(39.3041347756603,-80.34428358078));
       var ls = new Array('<p align="left"><font face="Tahoma, Arial, Helvetica" size="2"><nobr><b>Christian Apostolic Church (UPC)</b></nobr><br /><nobr>Rt. 3, Box 303C, Clarksburg, WV 26301</nobr><br /><img border="0" src="http://cac.us.com/images/map/CAC-bldg-for-map-marker.png" width="65" height="44" align="left" hspace="0" /><nobr>(On N. 20th St at Arlington.)</nobr><br /><nobr>&nbsp;&nbsp;<a href="http://cac.us.com">cac.us.com</a> • 304.624.4459</nobr><br /><nobr>&nbsp;&nbsp;<a href="mailto:pastor@cac.us.com">pastor@cac.us.com</a> • <a href="http://cac.us.com/map/">more</a></nobr></font><font style='font-size: 1pt'><br />&nbsp;</font></p>');
       var is = new Array(i1);

       for (var i = 0; i < 1; i++) {
         mrs[i] = createMarker(ps[i], ls[i], is[i]);
         map.openInfoWindowHtml(ps[i], ls[i]);
         map.addOverlay(mrs[i]);
       }
        

      }
     }
     //]]>
     //-->
     </script>


    Sincerely,
    Doug Joseph
    Filed under: ,
  •  01-04-2008, 5:41 PM 38203 in reply to 38195

    Re: Adding Google Maps

    Thanks this will be a good resource for me in the future I'm certain.

     


    Sincerely,

    Carl
    -----
    vine type - content management with standards in mind - vinetype.com
    -----
    Filed under: ,
View as RSS news feed in XML