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

PHP & Base de données Discussion :

Compter Nbres de clics sur marqueur google map API v3


Sujet :

PHP & Base de données

  1. #1
    Futur Membre du Club
    Inscrit en
    Octobre 2009
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Octobre 2009
    Messages : 9
    Points : 6
    Points
    6
    Par défaut Compter Nbres de clics sur marqueur google map API v3
    Bonjour,
    je fait appel à votre aide car je dois incrémenter un compteur à chaque clic sur un marqueur google map. Je dois réaliser cela en php car j'aurai un compteur pour chaque établissements de ma base de donnée (variable cpt+id_établissement).

    Comment puis-je faire cela ???

    voici mon code php :

    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
     
    if(isset($_GET['google_map']))  // Page Google Map de l'établissement
    {
     echo'<div id="contenu"><h2 style="text-align:center;padding-top:15px;padding-bottom:15px;color:#666666;font-style:italic;">Google Map</h2>';
    require('includes/GoogleMapAPIv3.class.php');
    $query = 'SELECT * FROM t_etablissement WHERE t_etablissement.id_etablissement = '.$_GET['google_map'].'';
    $result = mysql_query($query)
    or die ('Impossible d\'exécuter la requête');
    $row = mysql_fetch_array($result);
    $gmap = new GoogleMapAPI();
    $gmap->setSize('750px','500px');
    //$gmap->setZoom(11);
    $gmap->setLang('fr');
    $letters = array("é", "è", "ê", "ë");
    $address = str_replace($letters,'e',$row['adresse_etablissement']); 
    $title = $row['nom_etablissement'];
    $centre = $address;
    $gmap->setCenter($address);
    $content = '<ul><li>'.$title.'</li><li>'.$row['adresse_etablissement'].'</li><li>Tél: '.$row['telephone_etablissement'].'- Fax: '.$row['fax_etablissement'].'</li><li>'.$row['website_etablissement'].'</li><li><img src=\'includes/photo/etab1.1.jpg\'></li></ul>';
    $gmap->addMarkerByAddress($address, $title, $content); 
    $gmap->generate();
    $map = $gmap->getGoogleMap();
    echo'<div style="margin-left:15px;margin-right:15px;border:2px solid black;">'.$map.'</div>';
    echo'</div>'; 
    }
    et voici le contenu du fichier GoogleMapAPIv3.class.php :

    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
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
     
    <?php
     
    class GoogleMapAPI
    {
    	/** GoogleMap ID for the HTML DIV  **/
    	protected $googleMapId = 'googlemapapi';
     
    	/** GoogleMap  Direction ID for the HTML DIV **/
    	protected $googleMapDirectionId = 'route';
     
    	/** Width of the gmap **/
    	protected $width = '';
     
    	/** Height of the gmap **/
    	protected $height = '';
     
    	/** Icon width of the gmarker **/
    	protected $iconWidth = 57;
     
    	/** Icon height of the gmarker **/
    	protected $iconHeight = 34;
     
    	/** Infowindow width of the gmarker **/
    	protected $infoWindowWidth = 250;
     
    	/** Default zoom of the gmap **/
    	protected $zoom = 9;
     
    	/** Enable the zoom of the Infowindow **/
    	protected $enableWindowZoom = false;
     
    	/** Default zoom of the Infowindow **/
    	protected $infoWindowZoom = 3;
     
    	/** Lang of the gmap **/
    	protected $lang = 'fr';
     
    	/**Center of the gmap **/
    	protected $center = 'Namur Belgique';
     
    	/** Content of the HTML generated **/
    	protected $content = '';
     
    	/** Add the direction button to the infowindow **/
    	protected $displayDirectionFields = false;
     
    	/** Hide the marker by default **/
    	protected $defaultHideMarker = false;
     
    	/** Extra content (marker, etc...) **/
    	protected $contentMarker = '';
     
    	/** Use clusterer to display a lot of markers on the gmap **/
    	protected $useClusterer = false;
    	protected $gridSize = 100;
    	protected $maxZoom = 9;
    	protected $clustererLibrarypath = 'http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_packed.js';
     
    	/** Enable automatic center/zoom **/
    	protected $enableAutomaticCenterZoom = false;
     
    	/** maximum longitude of all markers **/
    	protected $maxLng = -1000000;
     
    	/** minimum longitude of all markers **/
    	protected $minLng = 1000000;
     
    	/** max latitude of all markers **/
    	protected $maxLat = -1000000;
     
    	/** min latitude of all markers **/
    	protected $minLat = 1000000;
     
    	/** map center latitude (horizontal), calculated automatically as markers are added to the map **/
    	protected $centerLat = null;
     
    	/** map center longitude (vertical),  calculated automatically as markers are added to the map **/
    	protected $centerLng = null;
     
    	/** factor by which to fudge the boundaries so that when we zoom encompass, the markers aren't too close to the edge **/
    	protected $coordCoef = 0.01;
     
    	/** Type of map to display **/
    	protected $mapType = 'ROADMAP';
     
    	/**
    	 * Class constructor
    	 *
    	 * @return void
    	 */
     
    	public function __construct()
    	{
    	}
     
    	/**
    	 * Set the useClusterer parameter (optimization to display a lot of marker)
    	 *
    	 * @param boolean $useClusterer use cluster or not
    	 * @param int $gridSize grid size (The grid size of a cluster in pixel. Each cluster will be a square. If you want the algorithm to run faster, you can set this value larger. The default value is 100.)
    	 * @param int $maxZoom maxZoom (The max zoom level monitored by a marker cluster. If not given, the marker cluster assumes the maximum map zoom level. When maxZoom is reached or exceeded all markers will be shown without cluster.)
    	 * @param int $clustererLibraryPath clustererLibraryPath
    	 *
    	 * @return void
    	 */
     
    	public function setClusterer($useClusterer, $gridSize = 100, $maxZoom = 9, $clustererLibraryPath = '')
    	{
    		$this->useClusterer = $useClusterer;
    		$this->gridSize = $gridSize;
    		$this->maxZoom = $maxZoom;
    		($clustererLibraryPath == '') ? $this->clustererLibraryPath = 'http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_packed.js' : $clustererLibraryPath;
    	}
     
    	/**
    	 * Set the type of map, can be :
    	 * HYBRID, TERRAIN, ROADMAP, SATELLITE
    	 *
    	 * @param string $type
    	 * @return void
    	 */
    	public function setMapType($type)
    	{
    		$mapsType = array('ROADMAP', 'HYBRID', 'TERRAIN', 'SATELLITE');
    		if (!in_array(strtoupper($type), $mapsType)) {
    			$this->mapType = $mapsType[0];
    		} else {
    			$this->mapType = strtoupper($type);
    		}
    	}
     
     
    	/**
    	 * Set the ID of the default gmap DIV
    	 *
    	 * @param string $googleMapId the google div ID
    	 *
    	 * @return void
    	 */
     
    	public function setDivId($googleMapId)
    	{
    		$this->googleMapId = $googleMapId;
    	}
     
    	/**
    	 * Set the ID of the default gmap direction DIV
    	 *
    	 * @param string $googleMapDirectionId GoogleMap  Direction ID for the HTML DIV
    	 *
    	 * @return void
    	 */
     
    	public function setDirectionDivId($googleMapDirectionId)
    	{
    		$this->googleMapDirectionId = $googleMapDirectionId;
    	}
     
    	/**
    	 * Set the size of the gmap
    	 *
    	 * @param int $width GoogleMap  width
    	 * @param int $height GoogleMap  height
    	 *
    	 * @return void
    	 */
     
    	public function setSize($width, $height)
    	{
    		$this->width = $width;
    		$this->height = $height;
    	}
     
    	/**
    	 * Set the with of the gmap infowindow (on marker clik)
    	 *
    	 * @param int $infoWindowWidth GoogleMap  info window width
    	 *
    	 * @return void
    	 */
     
    	public function setInfoWindowWidth($infoWindowWidth)
    	{
    		$this->infoWindowWidth = $infoWindowWidth;
    	}
     
    	/**
    	 * Set the size of the icon markers
    	 *
    	 * @param int $iconWidth GoogleMap  marker icon width
    	 * @param int $iconHeight GoogleMap  marker icon height
    	 *
    	 * @return void
    	 */
     
    	public function setIconSize($iconWidth, $iconHeight)
    	{
    		$this->iconWidth = $iconWidth;
    		$this->iconHeight = $iconHeight;
    	}
     
    	/**
    	 * Set the lang of the gmap
    	 *
    	 * @param string $lang GoogleMap  lang : fr,en,..
    	 *
    	 * @return void
    	 */
     
    	public function setLang($lang)
    	{
    		$this->lang = $lang;
    	}
     
    	/**
    	 * Set the zoom of the gmap
    	 *
    	 * @param int $zoom GoogleMap  zoom.
    	 *
    	 * @return void
    	 */
     
    	public function setZoom($zoom)
    	{
    		$this->zoom = $zoom;
    	}
     
    	/**
    	 * Set the zoom of the infowindow
    	 *
    	 * @param int $zoom GoogleMap  zoom.
    	 *
    	 * @return void
    	 */
     
    	public function setInfoWindowZoom($infoWindowZoom)
    	{
    		$this->infoWindowZoom = $infoWindowZoom;
    	}
     
    	/**
    	 * Enable the zoom on the marker when you click on it
    	 *
    	 * @param int $zoom GoogleMap  zoom.
    	 *
    	 * @return void
    	 */
     
    	public function setEnableWindowZoom($enableWindowZoom)
    	{
    		$this->enableWindowZoom = $enableWindowZoom;
    	}
     
    	/**
    	 * Enable theautomatic center/zoom at the gmap load
    	 *
    	 * @param int $zoom GoogleMap  zoom.
    	 *
    	 * @return void
    	 */
     
    	public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom)
    	{
    		$this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom;
    	}
     
    	/**
    	 * Set the center of the gmap (an address)
    	 *
    	 * @param string $center GoogleMap  center (an address)
    	 *
    	 * @return void
    	 */
     
    	public function setCenter($center)
    	{
    		$this->center = $center;
    	}
     
    	/**
    	 * Set the center of the gmap
    	 *
    	 * @param boolean $displayDirectionFields display directions or not in the info window
    	 *
    	 * @return void
    	 */
     
    	public function setDisplayDirectionFields($displayDirectionFields)
    	{
    		$this->displayDirectionFields = $displayDirectionFields;
    	}
     
    	/**
    	 * Set the defaultHideMarker
    	 *
    	 * @param boolean $defaultHideMarker hide all the markers on the map by default
    	 *
    	 * @return void
    	 */
     
    	public function setDefaultHideMarker($defaultHideMarker)
    	{
    		$this->defaultHideMarker = $defaultHideMarker;
    	}
     
    	/**
    	 * Get the google map content
    	 *
    	 * @return string the google map html code
    	 */
     
    	public function getGoogleMap()
    	{
    		return $this->content;
    	}
     
    	/**
    	 * Get URL content using cURL.
    	 *
    	 * @param string $url the url
    	 *
    	 * @return string the html code
    	 *
    	 * @todo add proxy settings
    	 */
     
    	public function getContent($url)
    	{
    		$curl = curl_init();
    		curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    		curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
    		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
    		curl_setopt($curl, CURLOPT_URL, $url);
    		$data = curl_exec($curl);
    		curl_close($curl);
    		return $data;
    	}
     
    	/**
    	 * Remove accentued characters
    	 *
    	 * @param string $chaine		The string to treat
    	 * @param string $remplace_par	The replacement character
    	 * @return string
    	 */
    	public function withoutSpecialChars($text, $replaceBy = '_')
    	{
    		$accents = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ";
    		$sansAccents = "AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy";
    		$text = strtr($text, $accents, $sansAccents);
    		$text = preg_replace('/([^.a-z0-9]+)/i', $replaceBy, $text);
    		return $text;
    	}
     
     
    	/**
    	 * Geocoding an address (address -> lat,lng)
    	 *
    	 * @param string $address an address
    	 *
    	 * @return array array with precision, lat & lng
    	 */
     
    	public function geocoding($address)
    	{
    		$encodeAddress = urlencode($this->withoutSpecialChars($address));
    		$url = "http://maps.google.com/maps/geo?q=".$encodeAddress."&output=csv";
     
    		if (function_exists('curl_init')) {
    			$data = $this->getContent($url);
    		} else {
    			$data = file_get_contents($url);
    		}
     
    		$csvSplit = preg_split("/,/", $data);
    		$status = $csvSplit[0];
     
    		if (strcmp($status, "200") == 0) {
    			$return = $csvSplit; // successful geocode, $precision = $csvSplit[1],$lat = $csvSplit[2],$lng = $csvSplit[3];
    		} else {
    			echo "<!-- geocoding : failure to geocode : " . $status . " -->\n";
    			$return = null; // failure to geocode
    		}
     
    		return $return;
    	}
     
    	/**
    	 * Add marker by his coord
    	 *
    	 * @param string $lat lat
    	 * @param string $lng lngs
    	 * @param string $html html code display in the info window
    	 * @param string $category marker category
    	 * @param string $icon an icon url
    	 *
    	 * @return void
    	 */
     
    	public function addMarkerByCoords($lat, $lng, $title, $html = '', $category = '', $icon = '')
    	{
    		if ($icon == '') {
    			$icon = 'http://maps.gstatic.com/intl/fr_ALL/mapfiles/markers/marker_sprite.png';
    		}
     
    		// Save the lat/lon to enable the automatic center/zoom
    		$this->maxLng = (float)max((float)$lng, $this->maxLng);
    		$this->minLng = (float)min((float)$lng, $this->minLng);
    		$this->maxLat = (float)max((float)$lat, $this->maxLat);
    		$this->minLat = (float)min((float)$lat, $this->minLat);
    		$this->centerLng = (float)($this->minLng + $this->maxLng) / 2;
    		$this->centerLat = (float)($this->minLat + $this->maxLat) / 2;
     
    		$this->contentMarker .= "\t" . 'addMarker(new google.maps.LatLng("' . $lat . '","' . $lng . '"),"' . $title . '","' . $html . '","' . $category . '","' . $icon . '");' . "\n";
    	}
     
    	/**
    	 * Add marker by his address
    	 *
    	 * @param string $address an ddress
    	 * @param string $content html code display in the info window
    	 * @param string $category marker category
    	 * @param string $icon an icon url
    	 *
    	 * @return void
    	 */
     
    	public function addMarkerByAddress($address, $title = '', $content = '', $category = '', $icon = '')
    	{
    		$point = $this->geocoding($address);
    		if ($point !== null) {
    			$this->addMarkerByCoords($point[2], $point[3], $title, $content, $category, $icon);
    		} else {
    			echo "<!-- addMarkerByAddress : ADDRESS NOT FOUND " . strip_tags($address) . " -->\n";
    			// throw new Exception('Adress not found : '.$address);
    		}
    	}
     
    	/**
    	 * Add marker by an array of coord
    	 *
    	 * @param string $coordtab an array of lat,lng,content
    	 * @param string $category marker category
    	 * @param string $icon an icon url
    	 *
    	 * @return void
    	 */
     
    	public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '')
    	{
    		foreach ($coordtab as $coord) {
    			$this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $coord[3], $category, $icon);
    		}
    	}
     
    	/**
    	 * Add marker by an array of address
    	 *
    	 * @param string $coordtab an array of address
    	 * @param string $category marker category
    	 * @param string $icon an icon url
    	 *
    	 * @return void
    	 */
     
    	public function addArrayMarkerByAddress($coordtab, $category = '', $icon = '')
    	{
    		foreach ($coordtab as $coord) {
    			$this->addMarkerByAddress($coord[0], $coord[1], $coord[2], $category, $icon);
    		}
    	}
     
    	/**
    	 * Set a direction between 2 addresss and set a text panel
    	 *
    	 * @param string $from an address
    	 * @param string $to an address
    	 *
    	 * @return void
    	 */
     
    	public function addDirection($from, $to)
    	{
    		$this->contentMarker .= 'addDirection("' . $from . '","' . $to . '");';
    	}
     
    	/**
    	 * Parse a KML file and add markers to a category
    	 *
    	 * @param string $url url of the kml file compatible with gmap and gearth
    	 * @param string $category marker category
    	 * @param string $icon an icon url
    	 *
    	 * @return void
    	 */
     
    	public function addKML($url, $category = '', $icon = '')
    	{
    		$xml = new SimpleXMLElement($url, null, true);
    		foreach ($xml->Document->Folder->Placemark as $item) {
    			$coordinates = explode(',', (string)$item->Point->coordinates);
    			$name = (string)$item->name;
    			$this->addMarkerByCoords($coordinates[1], $coordinates[0], $name, $name, $category, $icon);
    		}
    	}
     
    	/**
    	 * Initialize the javascript code
    	 *
    	 * @return void
    	 */
     
    	public function init()
    	{
    		// Google map DIV
    		if (($this->width != '') && ($this->height != '')) {
    			$this->content .= "\t" . '<div id="' . $this->googleMapId . '" style="width:' . $this->width . ';height:' . $this->height . '"></div>' . "\n";
    		} else {
    			$this->content .= "\t" . '<div id="' . $this->googleMapId . '"></div>' . "\n";
    		}
     
     
    		// Google map JS
    		$this->content .= '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=' . $this->lang . '">';
    		$this->content .= '</script>' . "\n";
     
    		// Clusterer JS
    		if ($this->useClusterer == true) {
    			$this->content .= '<script src="' . $this->clustererLibraryPath . '" type="text/javascript"></script>' . "\n";
    		}
     
    		$this->content .= '<script type="text/javascript">' . "\n";
     
    		//global variables
    		$this->content .= 'var geocoder = new google.maps.Geocoder();' . "\n";
    		$this->content .= 'var map;' . "\n";
    		$this->content .= 'var gmarkers = [];' . "\n";
    		$this->content .= 'var infowindow;' . "\n";
    		$this->content .= 'var directions = new google.maps.DirectionsRenderer();' . "\n";
    		$this->content .= 'var directionsService = new google.maps.DirectionsService();' . "\n";
    		$this->content .= 'var current_lat = 0;' . "\n";
    		$this->content .= 'var current_lng = 0;' . "\n";
     
    		// JS public function to get current Lat & Lng
    		$this->content .= "\t" . 'function getCurrentLat() {' . "\n";
    		$this->content .= "\t\t" . 'return current_lat;' . "\n";
    		$this->content .= "\t" . '}' . "\n";
    		$this->content .= "\t" . 'function getCurrentLng() {' . "\n";
    		$this->content .= "\t\t" . 'return current_lng;' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to add a  marker 
    		$this->content .= "\t" . 'function addMarker(latlng,title,content,category,icon) {' . "\n";
    		$this->content .= "\t\t" . 'var marker = new google.maps.Marker({' . "\n";
    		$this->content .= "\t\t\t" . 'map: map,' . "\n";
    		$this->content .= "\t\t\t" . 'title : title,' . "\n";
    		$this->content .= "\t\t\t" . 'icon:  new google.maps.MarkerImage(icon, new google.maps.Size(' . $this->iconWidth . ',' . $this->iconHeight . ')),' . "\n";
    		$this->content .= "\t\t\t" . 'position: latlng' . "\n";
    		$this->content .= "\t\t" . '});' . "\n";
     
    		// Display direction inputs in the info window
    		if ($this->displayDirectionFields == true) {
    			$this->content .= "\t\t" . 'content += \'<div style="clear:both;height:20px;"></div>\';' . "\n";
    			$this->content .= "\t\t" . 'id_name = \'marker_\'+gmarkers.length;' . "\n";
    			$this->content .= "\t\t" . 'content += \'<input type="text" id="\'+id_name+\'"/>\';' . "\n";
    			$this->content .= "\t\t" . 'var from = ""+latlng.lat()+","+latlng.lng();' . "\n";
    			$this->content .= "\t\t" . 'content += \'<br /><input type="button" onClick="addDirection(to.value,document.getElementById(\\\'\'+id_name+\'\\\').value);" value="Arrivée"/>\';' . "\n";
                $this->content .= "\t\t" . 'content += \'<input type="button" onClick="addDirection(document.getElementById(\\\'\'+id_name+\'\\\').value,to.value);" value="Départ"/>\';' . "\n";
    		}
     
    		$this->content .= "\t\t" . 'var html = \'<div style="float:left;text-align:left;width:' . $this->infoWindowWidth . ';">\'+content+\'</div>\'' . "\n";
    		$this->content .= "\t\t" . 'google.maps.event.addListener(marker, "click", function() {' . "\n";
    		$this->content .= "\t\t\t" . 'if (infowindow) infowindow.close();' . "\n";
    		$this->content .= "\t\t\t" . 'infowindow = new google.maps.InfoWindow({content: html});' . "\n";
    		$this->content .= "\t\t\t" . 'infowindow.open(map,marker);' . "\n";
     
    		// Enable the zoom when you click on a marker
    		if ($this->enableWindowZoom == true) {
    			$this->content .= "\t\t" . 'map.setCenter(new google.maps.LatLng(latlng.lat(),latlng.lng()),' . $this->infoWindowZoom . ');' . "\n";
    		}
     
    		$this->content .= "\t\t" . '});' . "\n";
    		$this->content .= "\t\t" . 'marker.mycategory = category;' . "\n";
    		$this->content .= "\t\t" . 'gmarkers.push(marker);' . "\n";
     
    		// Hide marker by default
    		if ($this->defaultHideMarker == true) {
    			$this->content .= "\t\t" . 'marker.setVisible(false);' . "\n";
    		}
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to add a geocode marker 
    		$this->content .= "\t" . 'function geocodeMarker(address,title,content,category,icon) {' . "\n";
    		$this->content .= "\t\t" . 'if (geocoder) {' . "\n";
    		$this->content .= "\t\t\t" . 'geocoder.geocode( { "address" : address}, function(results, status) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'if (status == google.maps.GeocoderStatus.OK) {' . "\n";
    		$this->content .= "\t\t\t\t\t" . 'var latlng = 	results[0].geometry.location;' . "\n";
    		$this->content .= "\t\t\t\t\t" . 'addMarker(results[0].geometry.location,title,content,category,icon)' . "\n";
    		$this->content .= "\t\t\t\t" . '}' . "\n";
    		$this->content .= "\t\t\t" . '});' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to center the gmaps dynamically
    		$this->content .= "\t" . 'function geocodeCenter(address) {' . "\n";
    		$this->content .= "\t\t" . 'if (geocoder) {' . "\n";
    		$this->content .= "\t\t\t" . 'geocoder.geocode( { "address": address}, function(results, status) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'if (status == google.maps.GeocoderStatus.OK) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'map.setCenter(results[0].geometry.location);' . "\n";
    		$this->content .= "\t\t\t\t" . '} else {' . "\n";
    		$this->content .= "\t\t\t\t" . 'alert("Geocode was not successful for the following reason: " + status);' . "\n";
    		$this->content .= "\t\t\t\t" . '}' . "\n";
    		$this->content .= "\t\t\t" . '});' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to set direction
    		$this->content .= "\t" . 'function addDirection(from,to) {' . "\n";
    		$this->content .= "\t\t" . 'var request = {' . "\n";
    		$this->content .= "\t\t" . 'origin:from, ' . "\n";
    		$this->content .= "\t\t" . 'destination:to,' . "\n";
    		$this->content .= "\t\t" . 'travelMode: google.maps.DirectionsTravelMode.DRIVING' . "\n";
    		$this->content .= "\t\t" . '};' . "\n";
    		$this->content .= "\t\t" . 'directionsService.route(request, function(response, status) {' . "\n";
    		$this->content .= "\t\t" . 'if (status == google.maps.DirectionsStatus.OK) {' . "\n";
    		$this->content .= "\t\t" . 'directions.setDirections(response);' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . '});' . "\n";
     
    		$this->content .= "\t\t" . 'if(infowindow) { infowindow.close(); }' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to show a category of marker
    		$this->content .= "\t" . 'function showCategory(category) {' . "\n";
    		$this->content .= "\t\t" . 'for (var i=0; i<gmarkers.length; i++) {' . "\n";
    		$this->content .= "\t\t\t" . 'if (gmarkers[i].mycategory == category) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'gmarkers[i].setVisible(true);' . "\n";
    		$this->content .= "\t\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to hide a category of marker
    		$this->content .= "\t" . 'function hideCategory(category) {' . "\n";
    		$this->content .= "\t\t" . 'for (var i=0; i<gmarkers.length; i++) {' . "\n";
    		$this->content .= "\t\t\t" . 'if (gmarkers[i].mycategory == category) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'gmarkers[i].setVisible(false);' . "\n";
    		$this->content .= "\t\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . 'if(infowindow) { infowindow.close(); }' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to hide all the markers
    		$this->content .= "\t" . 'function hideAll() {' . "\n";
    		$this->content .= "\t\t" . 'for (var i=0; i<gmarkers.length; i++) {' . "\n";
    		$this->content .= "\t\t\t" . 'gmarkers[i].setVisible(false);' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . 'if(infowindow) { infowindow.close(); }' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to show all the markers
    		$this->content .= "\t" . 'function showAll() {' . "\n";
    		$this->content .= "\t\t" . 'for (var i=0; i<gmarkers.length; i++) {' . "\n";
    		$this->content .= "\t\t\t" . 'gmarkers[i].setVisible(true);' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . 'if(infowindow) { infowindow.close(); }' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function to hide/show a category of marker - TODO BUG
    		$this->content .= "\t" . 'function toggleHideShow(category) {' . "\n";
    		$this->content .= "\t\t" . 'for (var i=0; i<gmarkers.length; i++) {' . "\n";
    		$this->content .= "\t\t\t" . 'if (gmarkers[i].mycategory === category) {' . "\n";
    		$this->content .= "\t\t\t\t" . 'if (gmarkers[i].getVisible()===true) { gmarkers[i].setVisible(false); }' . "\n";
    		$this->content .= "\t\t\t\t" . 'else gmarkers[i].setVisible(true);' . "\n";
    		$this->content .= "\t\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . '}' . "\n";
    		$this->content .= "\t\t" . 'if(infowindow) { infowindow.close(); }' . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		// JS public function add a KML
    		$this->content .= "\t" . 'function addKML(file) {' . "\n";
    		$this->content .= "\t\t" . 'var ctaLayer = new google.maps.KmlLayer(file);' . "\n";
    		$this->content .= "\t\t" . 'ctaLayer.setMap(map);' . "\n";
    		$this->content .= "\t" . '}' . "\n";
    	}
     
    	public function generate()
    	{
    		$this->init();
     
    		//Fonction init()
    		$this->content .= "\t" . 'function initialize() {' . "\n";
    		$this->content .= "\t" . 'var myLatlng = new google.maps.LatLng(48.8792,2.34778);' . "\n";
    		$this->content .= "\t" . 'var myOptions = {' . "\n";
    		$this->content .= "\t\t" . 'zoom: ' . $this->zoom . ',' . "\n";
    		$this->content .= "\t\t" . 'center: myLatlng,' . "\n";
    		$this->content .= "\t\t" . 'mapTypeId: google.maps.MapTypeId.' . $this->mapType . "\n";
    		$this->content .= "\t" . '}' . "\n";
     
    		//Goole map Div Id
    		$this->content .= "\t" . 'map = new google.maps.Map(document.getElementById("' . $this->googleMapId . '"), myOptions);' . "\n";
     
    		// Center
    		if ($this->enableAutomaticCenterZoom == true) {
    			$lenLng = $this->maxLng - $this->minLng;
    			$lenLat = $this->maxLat - $this->minLat;
    			$this->minLng -= $lenLng * $this->coordCoef;
    			$this->maxLng += $lenLng * $this->coordCoef;
    			$this->minLat -= $lenLat * $this->coordCoef;
    			$this->maxLat += $lenLat * $this->coordCoef;
     
    			$minLat = number_format(floatval($this->minLat), 12, '.', '');
    			$minLng = number_format(floatval($this->minLng), 12, '.', '');
    			$maxLat = number_format(floatval($this->maxLat), 12, '.', '');
    			$maxLng = number_format(floatval($this->maxLng), 12, '.', '');
    			$this->content .= "\t\t\t" . 'var bds = new google.maps.LatLngBounds(new google.maps.LatLng(' . $minLat . ',' . $minLng . '),new google.maps.LatLng(' . $maxLat . ',' . $maxLng . '));' . "\n";
    			$this->content .= "\t\t\t" . 'map.fitBounds(bds);' . "\n";
    		} else {
    			$this->content .= "\t" . 'geocodeCenter("' . $this->center . '");' . "\n";
    		}
     
    		$this->content .= "\t" . 'google.maps.event.addListener(map,"click",function(event) { if (event) { current_lat=event.latLng.lat();current_lng=event.latLng.lng(); }}) ;' . "\n";
     
    		$this->content .= "\t" . 'directions.setMap(map);' . "\n";
    		$this->content .= "\t" . 'directions.setPanel(document.getElementById("' . $this->googleMapDirectionId . '"))' . "\n";
     
    		// add all the markers
    		$this->content .= $this->contentMarker;
     
    		// Clusterer JS
    		if ($this->useClusterer == true) {
    			$this->content .= "\t" . 'var markerCluster = new MarkerClusterer(map, gmarkers,{gridSize: ' . $this->gridSize . ', maxZoom: ' . $this->maxZoom . '});' . "\n";
    		}
     
    		$this->content .= '}' . "\n";
     
    		// Chargement de la map a la fin du HTML
    		$this->content .= "\t" . 'window.onload=initialize;' . "\n";
     
    		//Fermeture du javascript
    		$this->content .= '</script>' . "\n";
     
    	}
     
    }

  2. #2
    Membre expert
    Avatar de ericd69
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2011
    Messages
    1 919
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2011
    Messages : 1 919
    Points : 3 295
    Points
    3 295
    Billets dans le blog
    1
    Par défaut
    salut,

    je pense que tu devrais utiliser ajax pour renvoyer l'identifiant de l'établissement (ou son nom) à un script php qui incrémente ce qu'il faut dans ta bd...

    L'envoi se déclenchant sur le clic sur le marker (si tu peux lui associer une fonction javascript)
    soyons pensez à mettre quand votre problème est résolu ou à utiliser pour les réponses pertinentes...
    ne posez pas de problématique soi-disant simplifiée sur des problèmes que vous n'êtes pas capable de résoudre par respect pour ceux qui planchent dessus... sinon: et à utiliser pour insérer votre code...

  3. #3
    Membre éprouvé Avatar de Marc3001
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2008
    Messages
    829
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux

    Informations forums :
    Inscription : Février 2008
    Messages : 829
    Points : 1 275
    Points
    1 275
    Par défaut
    Le clic c'est une action sur le client et donc ne peut être géré en php.

    Tu dois utiliser javascript pour intercepter le clic et effectuer les actions que tu veux....
    Le logiciel, c'est comme le sexe, c'est meilleur quand c'est libre.

    Linus Torvalds

Discussions similaires

  1. [Google Maps] Ajouter un marqueur sur le google maps quand on cherche un endroit
    Par sonny.ng dans le forum APIs Google
    Réponses: 2
    Dernier message: 28/06/2014, 13h16
  2. [Google Maps] Adresse d'un marqueur Google Map API
    Par iBen68 dans le forum APIs Google
    Réponses: 2
    Dernier message: 12/06/2012, 22h19
  3. [Google Maps] / Scripts : Marqueurs Google Maps non affichés sur Internet Explorer 7 & 8
    Par exilquery dans le forum APIs Google
    Réponses: 3
    Dernier message: 21/09/2011, 23h18
  4. [Google Maps] Rendre invisible mes marqueurs Google Map API v3
    Par tonymx15 dans le forum APIs Google
    Réponses: 5
    Dernier message: 09/04/2011, 10h36
  5. Marqueur Google Maps
    Par lelectronique.com dans le forum APIs
    Réponses: 1
    Dernier message: 07/02/2009, 14h39

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