IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

APIs Google Discussion :

Fonction Recherche d'une adresse et les marqueurs [Google Maps]


Sujet :

APIs Google

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2014
    Messages : 4
    Points : 3
    Points
    3
    Par défaut Fonction Recherche d'une adresse et les marqueurs
    Bonjour à tous,

    Je suis en train de travailler sur le Google Maps api v3, et j'ai plusieurs de difficultés. J'aimerais bien avoir des aides .
    Mon plan Google Maps a 24 restaurants qui sont autour de Paris et une barre de recherche d’adresse qui a pour objectif de trouver les endroits où les clients souhaitent trouver un des nos restaurants. J'ai arrivé à ajouter 24 marqueurs pour 24 restaurants. Mais la fonction de recherche d'une adresse ne marche pas.

    Je souhaiterais :
    -Quand un client recherche un endroit, cette fonction va ajouter un marqueur de cet endroit
    -En deuxième temps, je voudrais ajouter les informations de chaque restaurant. Le tableau qui contient les informations des restaurant, c'est comme ca:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
     // Table of Restaurants
            var myLatlng = [
     
              ['Fontaines Saint-Honoré','A partir de 15.00 €',48.862679,2.337809],			// 1 Fontaines Saint-Honoré			
              ['Auberge du Louvre','A partir de 14.50 €',48.8615084,2.3422163],		//2 Auberge du Louvre						
              ['Paris en Scène','A partir de 33.00 €',48.85434,2.34481],				//3 Paris en Scène
              ['Jules','A partir de 13.60 €',48.851623,2.35628],			//4 Jules
              ['Bastide Odéon','A partir de 25.00 €',48.8492828,2.3391192],		//5Bastide Odéon
              ['Chez Françoise','A partir de 26.00 €',48.8620976,2.3148948],		//6Chez Françoise
              ['Le Louis XVI','A partir de 15.80 €',48.8733581,2.3236535],		//7Le Louis XVI
              ['La Marée','A partir de 26.00 €',48.8773165,2.3004392],		//8La Marée
              ['Le Panorama','A partir de 11.50 €',48.8831709,2.3467466],		//9Le Panorama
              ['Le Faux Filet','A partir de 16.40 €',48.874732,2.3309639],		//10Le Faux Filet
              ['Les Barjots','A partir de 12.60 €',48.8499497,2.3857454],		//11Les Barjots
              ['Pataquès','A partir de 16.50 €',48.8399965,2.3812885],		//12Pataquès
              ['Oskian','A partir de 13.00 €',48.8617444,2.3408514],		//13L'Oskian
              ['Les Diamantaires','A partir de 17.00 €',48.875373,2.342784],			//14Les Diamantaires
              ['Evidence','A partir de 13.80 €',48.869100,2.362401],			//15L'Evidence
              ['Les Ambassades','A partir de 16.00 €',48.889100,2.343851],			//16Les Ambassades
              ['La Casa','A partir de 13.00 €',48.887633,2.389992],			//17La Casa
              ['Bistrot de la Montagne','A partir de 15.40 €',48.8479408,2.3484857],		//18Bistrot de la Montagne
              ['Au coeur du 9ème','A partir de 10.90 €',48.875500,2.342347],			//19Au coeur du 9ème
              ['Au Petit Marguery','A partir de 26.00 €',48.8794724,2.2908418],		//20Au Petit Marguery
              ['Capitaine Fracasse ','A partir de 49.00 €',48.85554,2.28744,300],				//21Capitaine Fracasse 
              ['Chez Frezet','A partir de 23.00 €',48.893750,2.335581],			//22Chez Frezet
              ['Martha Café','A partir de 13.60 €',48.874501,2.291863],			//23Martha's Café
              ['Monte Carlo ','A partir de 11.50 €',48.8754392,2.2961331]		//24Monte Carlo  
              ];

    Voici mon code du plan Google Maps
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
     
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
    		<meta charset="UTF-8" />
    		<title>Club des Restaurants de Paris</title>
    		<style type="text/css">
     
    		#conteneur_google_map
    			{
    				width: 100%;
    				height: 30%;
    				margin-top : 0px;
    				margin :auto;	
    				font-family: Arial, Helvetica, Verdana, sans-serif;
    				font-size: 12px;
    				color: #ffffff;
    				border: 0px solid #840B37;
    			}
     
    			#EmplacementDeMaCarte {
    				height: 100%;
    			}
     
    			.popup 
    			{
    				font-family:Arial, Helvetica, sans-serif;
    				height:100px;
    				width:200px;
    				color:#183152;
    				font-size:12px;
    				text-align:left;
    			}
     
    			a, a:visited
    			{
    				color:#ffffff;
    				font-size:1.0em;
     
    			}
     
    			a:hover
    			{
    				color:#F63900;
    			}
     
    			.image_2
    			{
    				padding-left: 16px;
    			}
     
    			#map {
    			width: 100%; 
    			height: 600px;
    			margin:auto;
     
    			}
     
    			#plan
    			{
    				margin:auto;
    				padding-top:5px;
    				padding-bottom:10px;
    				width:auto;
    				height: 80px;
    				background-color:#840B37;
     
     
    			}
     
    			#plan a
    			{
    				text-decoration:none;
     
    			}
     
    			#colonne_gauche_google_map
    			{
    				float:left;
    				margin:auto;
    				width:auto;
    				height: auto;
    				padding-left:10px;
    				padding-right:10px;
    				margin-left:100px;
    				text-align:left;
    				border: 0px solid #40A497;
    			}
     
    			#colonne_centre_1_google_map
    			{
    				float:left;
    				margin:auto;
    				padding-left:10px;
    				padding-right:10px;
    				margin-left:100px;
    				width:auto;
    				height: auto;
    				text-align:left;
    				border: 0px solid #40A497;
    			}
    			#colonne_centre_2_google_map
    			{
    				float:left;
    				margin:auto;
    				padding-left:10px;
    				padding-right:10px;
    				margin-left:100px;
    				width:auto;
    				height: auto;
    				text-align:left;
    				text-color:#ffffff;
    				border: 0px solid #40A497;
    			}
    			#colonne_centre_3_google_map
    			{
    				float:left;
    				margin:auto;
    				padding-left:10px;
    				padding-right:10px;
    				margin-left:100px;
    				width:auto;
    				height: auto;
    				text-align:left;
    				border: 0px solid #40A497;
    			}
     
    			#colonne_droite_google_map
    			{
    				float:right;
    				text-align:right;
    				background-color:#840B37;
    			}
    		</style>
     
     
    	</head>	
        <body onload="initialize()">			
     
          <div id="conteneur_google_map">
     
        		<div style="font-family:arial,sans-serif;font-size:12px;">Adresse : 
    				<input type="text" style="font-family:arial,sans-serif;font-size:12px;" size="35" id="address" value="saisissez une adresse ou commune" onFocus="if (this.value=='saisissez une adresse ou commune') {this.value=''}"/>
        		<input type="submit" onclick="searchAddress()" class="b2 gkbutton" id="bell" value="Geocoder" style="display:inline">
        		<br></br>
        		</div>
    				<input type="hidden" id="coordonneesGPSdegLat" name="coordonneesGPSdegLat" value="coordonneesGPSdegLat" />
    				<input type="hidden" id="coordonneesGPSdegLng" name="coordonneesGPSdegLng" value="coordonneesGPSdegLng" />
     
            <div id="map"></div>
     
     
            <div id="plan">
                <div id="colonne_gauche_google_map">
     
    								<a href="javascript:openMarker(0);">Fontaines Saint-Honor&eacute;</a><br />
                    <a href="javascript:openMarker(1);">Auberge du Louvre</a><br />
                    <a href="javascript:openMarker(2)">Paris en Sc&egrave;ne</a><br />
                    <a href="javascript:openMarker(3)">Jules</a><br />
                    <a href="javascript:openMarker(4)">Bastide Od&eacute;on</a><br />
                    <a href="javascript:openMarker(5)">Chez Fran&ccedil;oise</a><br />
     
     
                </div>
                <div id="colonne_centre_1_google_map">
     
    								<a href="javascript:openMarker(6)">La Mar&eacute;e</a><br />
                    <a href="javascript:openMarker(7)">Le Louis XVI</a><br />
    								<a href="javascript:openMarker(8)">Le Panorama</a><br />
                    <a href="javascript:openMarker(9)">Le Faux Filet</a><br />
                    <a href="javascript:openMarker(10)">Les Barjots</a><br />
                    <a href="javascript:openMarker(11)">Pataqu&egrave;s</a><br />
     
                </div>
                <div id="colonne_centre_2_google_map">
     
    								<a href="javascript:openMarker(12)">L'Oskian</a><br />
                    <a href="javascript:openMarker(13)">Les Diamantaires</a><br />
                    <a href="javascript:openMarker(14)">L'Evidence</a><br />
                    <a href="javascript:openMarker(15)">Les Ambassades</a><br />
    								<a href="javascript:openMarker(16)">La Casa</a><br />
    								<a href="javascript:openMarker(17)">Bistrot de la Montagne</a><br />
     
     
               </div>
     
               <div id="colonne_centre_3_google_map">
     
    								<a href="javascript:openMarker(18)">Au coeur du 9&egrave;me</a><br />
                    <a href="javascript:openMarker(19)">Au Petit Marguery</a><br />
                    <a href="javascript:openMarker(20)">Capitaine Fracasse</a><br />
                    <a href="javascript:openMarker(21)">Chez Frezet</a><br />
                    <a href="javascript:openMarker(22)">Martha's Caf&eacute;</a><br />
                    <a href="javascript:openMarker(23)">Monte Carlo</a><br />
     
    						</div>
     
            </div>
           </div>
     
          <script type="text/javascript">
    		<!--
            var markerArray = [];
     
            function initialize() {
     
            // Table of Restaurants
            var myLatlng = [
     
              ['Fontaines Saint-Honoré','A partir de 15.00',48.862679,2.337809],			// 1 Fontaines Saint-Honoré			
              ['Auberge du Louvre','A partir de 14.50',48.8615084,2.3422163],		//2 Auberge du Louvre						
              ['Paris en Scène','A partir de 33.00',48.85434,2.34481],				//3 Paris en Scène
              ['Jules','A partir de 13.60',48.851623,2.35628],			//4 Jules
              ['Bastide Odéon','A partir de 25.00',48.8492828,2.3391192],		//5Bastide Odéon
              ['Chez Françoise','A partir de 26.00',48.8620976,2.3148948],		//6Chez Françoise
              ['Le Louis XVI','A partir de 15.80',48.8733581,2.3236535],		//7Le Louis XVI
              ['La Marée','A partir de 26.00',48.8773165,2.3004392],		//8La Marée
              ['Le Panorama','A partir de 11.50',48.8831709,2.3467466],		//9Le Panorama
              ['Le Faux Filet','A partir de 16.40',48.874732,2.3309639],		//10Le Faux Filet
              ['Les Barjots','A partir de 12.60',48.8499497,2.3857454],		//11Les Barjots
              ['Pataquès','A partir de 16.50',48.8399965,2.3812885],		//12Pataquès
              ['Oskian','A partir de 13.00',48.8617444,2.3408514],		//13L'Oskian
              ['Les Diamantaires','A partir de 17.00 €',48.875373,2.342784],			//14Les Diamantaires
              ['Evidence','A partir de 13.80 €',48.869100,2.362401],			//15L'Evidence
              ['Les Ambassades','A partir de 16.00 €',48.889100,2.343851],			//16Les Ambassades
              ['La Casa','A partir de 13.00 €',48.887633,2.389992],			//17La Casa
              ['Bistrot de la Montagne','A partir de 15.40 €',48.8479408,2.3484857],		//18Bistrot de la Montagne
              ['Au coeur du 9ème','A partir de 10.90 €',48.875500,2.342347],			//19Au coeur du 9ème
              ['Au Petit Marguery','A partir de 26.00 €',48.8794724,2.2908418],		//20Au Petit Marguery
              ['Capitaine Fracasse ','A partir de 49.00 €',48.85554,2.28744,300],				//21Capitaine Fracasse 
              ['Chez Frezet','A partir de 23.00 €',48.893750,2.335581],			//22Chez Frezet
              ['Martha Café','A partir de 13.60 €',48.874501,2.291863],			//23Martha's Café
              ['Monte Carlo ','A partir de 11.50 €',48.8754392,2.2961331]		//24Monte Carlo  
              ];
     
                // contient le html
                var locationsInfos;
                //Table infos of markers, etc.
                var locations = [];
     
                //Boucle pour remplir le tableau
                for (j = 0; j < 24; j++) { 
     
     			locationsInfos = '<div class="popup"><table border="1"><tr><td><img height ="60px" width="60px" src="http://leclubparis.fr/photo/logo du club newsletter.jpg" alt=""></td><br/><td>Restaurant '+(j+1)+'/24<br/></td></tr></table></div>';		
              //On remplit le tableau
    			locations.push([locationsInfos, myLatlng[j][2], myLatlng[j][3], 4,]);
    		};// en of loop
     
            var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 13,
              center: new google.maps.LatLng(48.864063, 2.339302, 4),
                  mapTypeControl: true,
                mapTypeControlOptions: {
              style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
            },
            navigationControl: true,
             navigationControlOptions: {
                style: google.maps.NavigationControlStyle.SMALL,
                position: google.maps.ControlPosition.TOP_RIGHT
            },
                scaleControl: true,
            streetViewControl: false,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            });
     
            var infowindow = new google.maps.InfoWindow();
     
            var marker, i;
     
            //var point = 0;
     
            // Boucle Create Markers
    		// Loop create markers
    			 var icon = new google.maps.MarkerImage('http://groupe-paris.com/newsletter/googlemap/marker.png');
     
           for (i = 0; i < locations.length; i++) { 
              marker = new google.maps.Marker({
                position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    						icon:icon,
     
                map: map
              });
     
              // Tableau : on stock les objets markers
    		  // Array : markers object
              markerArray.push(marker);
     
              google.maps.event.addListener(marker, 'click', (function(marker, i) {
                return function() {
                  infowindow.setContent(locations[i][0]);
                  infowindow.open(map, marker);
                }
              })(marker, i));
            }
     
            // test
     
            google.maps.event.addListener(map, 'click', function() {
              		infowindow.close();
              		infowindow.close(map, marker);
            	});
     
            }
     
            // This function picks up the click and opens the corresponding info window
    		function openMarker(i) {		 
                 //To force the click, 
                 //you need to call google.maps.event.trigger 
                 //which takes two params (instance, event)
                 google.maps.event.trigger(markerArray[i], 'click');
                 //map.setCenter(marker.position);
    	}
     
    //Geocoding an address	
    function searchAddress() {
    var address = document.getElementById("address").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
    document.getElementById('coordonneesGPSdegLat').value = results[0].geometry.location.lat();
    document.getElementById('coordonneesGPSdegLng').value = results[0].geometry.location.lng();
    map.setCenter(results[0].geometry.location);
    map.setZoom(14);
    var marker1 = new google.maps.Marker({
                map: map, 
                position: results[0].geometry.location,
    						draggable: true,
    						animation: google.maps.Animation.DROP
            });
    		var infoWindow = new google.maps.InfoWindow()
    	google.maps.event.addListener(marker1, 'dragend', function(event) {
        var myLatLng = event.latLng;
        var lat = myLatLng.lat();
        var lng = myLatLng.lng();
    	document.getElementById("coordonneesGPSdegLat").value = lat;
    	document.getElementById("coordonneesGPSdegLng").value = lng;
        infoWindow.setPosition(event.latLng);
        infoWindow.open(map);});
    	markers.push(marker1);
    	if(markers.length > 1)
    	markers[(i-1)].setMap(null);
    	i++;
         } else {alert("Le geocodage n\'a pu etre effectue pour la raison suivante: " + status);      }
        });
      }
     
     
    		  -->
          </script>
        </body>
     
    </html>
    Je vous remercie par avance . Et bon week-end

  2. #2
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    17 090
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 090
    Points : 44 661
    Points
    44 661
    Par défaut
    Bonjour,
    il y a beaucoup de manque dans ton code
    - le chargement de l'API
    - la déclaration des variables telle que geocoder

    Tout ceci est à corriger avant de continuer.
    Google Maps Javascript API V3 Reference

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2014
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2014
    Messages : 4
    Points : 3
    Points
    3
    Par défaut
    Merci de m'avoir aidé, mon code a marché.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problem avec la recherche d'une valeur dans les table
    Par anilane dans le forum Bases de données
    Réponses: 6
    Dernier message: 25/05/2007, 19h35
  2. recherche d'une adresse d'un tableau multidimensionnel
    Par tamara6 dans le forum Algorithmes et structures de données
    Réponses: 8
    Dernier message: 06/01/2007, 00h29
  3. Bouton de recherche d'une adresse de dossier
    Par crashyear dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 20/10/2006, 08h12
  4. Recherche d'une adresse MAC
    Par Stilobic dans le forum Administration
    Réponses: 5
    Dernier message: 19/01/2006, 18h13
  5. Clé matérielle - A la recherche d'une adresse ...
    Par B-Pascal dans le forum Ordinateurs
    Réponses: 6
    Dernier message: 09/11/2003, 15h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo