Ver Mensaje Individual
  #155 (permalink)  
Antiguo 27/11/2009, 08:34
Avatar de jahman
jahman
 
Fecha de Ingreso: noviembre-2003
Ubicación: Oslo
Mensajes: 230
Antigüedad: 20 años, 5 meses
Puntos: 0
Respuesta: FAQ´S del foro de Net

Tema: Multiples direccion api google maps c#
Pregunta: como mostrar multiples direcciones desde un string[]
Respuesta:

Code behind
Código:
        string[] Locations = { "0574 Oslo, Norge", "5143 Fyllingsdalen, Norge", "5561 Bokn, Norge", "2006 Løvenstad, Norge", "2410 Hernes, Norge", "1388 Borgen, Norge", "0674 Oslo, Norge", "3880 Dalen, Norge", "3036 Drammen, Norge", "0986 Oslo, Norge", "1363 Høvik, Norge", "1178 Oslo, Norge", "0971 Oslo, Norge", "6789 Loen, Norge", "1152 Oslo, Norge", "4017 Stavanger, Norge", "4900 Tvedestrand, Norge", "6869 Hafslo, Norge", "2750 Gran, Norge" };


                js.Text = @"<script type='text/javascript'>
                       function initialize() {
                        var lat;
                         var map = new GMap2(document.getElementById('mapsat'));
                         map.setCenter(new GLatLng(59.913820, 10.738741), 5);
                             map.addControl(new GMapTypeControl());
                            map.addControl(new GLargeMapControl());
                            map.addControl(new GScaleControl());
                         showAddress(map);
                        }
                    function showAddress(map) {     
                        var miIcono = new GIcon(G_DEFAULT_ICON);
                            miIcono.image = '../../images/for_sale.png';
   
                        geocoder = new GClientGeocoder();
                        if (geocoder) {";

        for (int idx = 0; idx < Locations.Length ; idx++)
        {
                Label1.Text += idx.ToString() + "-" + Locations[idx] + "<br>";
                js.Text += @"
                        geocoder.getLatLng('" + Locations[idx] + @"', function(point) {
                                alert(point+' - " + Locations[idx] + @"')
                                var marker = new GMarker(point,miIcono);
                                map.addOverlay(marker);
                                GEvent.addListener(marker, 'mouseover', function (){    marker.openInfoWindowHtml('" + idx.ToString() + "-" + Locations[idx] + @"');  })                              

                            });
                           
                        ";
                

        }
        js.Text += @"}}</script>";
maps.aspx
Código:
<head id="Head1" runat="server">
   <title>Multiples Direcciones en Google Map </title>
     <!--Google API reference-->
     <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=tuKey" type="text/javascript"></script>

</head>
    <body onload="initialize()">
        <form id="form1" runat="server">
       <asp:Panel ID="Panel1" runat="server">
           <!-- aca definimos un asp:literal para mostrar el javascript -->
           <asp:Literal ID="js" runat="server"></asp:Literal>
           <table >
            <tr>
                <td style="vertical-align:top">Label1<br /><asp:Label runat="server" ID="Label1"></asp:Label></td>
                <td><div id="mapsat" style="width: 600px; height: 600px; margin-bottom: 2px;"></div></td>
            </tr>
        </table>           
           
        </asp:Panel> 
        </form>

    </body>