Vous avez trouvé ce tutoriel intéressant ? Recommandez le en cliquant sur le bouton +1    

Obtenir une adresse postale à partir d'un LatLng

Tutoriel publié le Mis à jour le
Tutoriel en Français

Cette fonction vous permet d'obtenir l'adresse postale correspondant à un LatLng.

getAddress

Cet exemple affiche une infobulle contenant l'adresse postale du marqueur déplaçable (glissez et déposez le marqueur).

  
$('#maCarte').gmap3(
	{ 
		action: 'addMarker',
		latLng: [46.578498,2.457275],
		map:{
			center: true,
			zoom: 5,
			mapTypeId: google.maps.MapTypeId.TERRAIN
		},
		marker:{
			options:{
			draggable:true
			},
			events:{
				dragend: function(marker){
					$(this).gmap3(
						{
							action:'getAddress',
							latLng:marker.getPosition(),
							callback:function(results){
								var map = $(this).gmap3('get'),
									infowindow = $(this).gmap3({action:'get', name:'infowindow'}),
									content = results && results[1] ? results && results[1].formatted_address : 'Adresse inconnue';
								if (infowindow){
									infowindow.open(map, marker);
									infowindow.setContent(content);
								} else {
									$(this).gmap3({action:'addinfowindow', anchor:marker, options:{content: content}});
								}
							}
						}
					);
				}
			}
		}
	}
);

Carte avec getAddress

Code complet avec getAddress

<!DOCTYPE html>
<html lang="fr">
	<head>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
		<meta charset="UTF-8"/>
		<title>Votre titre de page</title>
		<style type="text/css">
			html { height: 100% }
			body { height: 100%; margin: 0px; padding: 0px }
			#maCarte { height: 100%; }
		</style>
		<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
		<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
		<script type="text/javascript" src="http://www.votredomaine.fr/js/gmap3.js"></script>
		<script type="text/javascript"> 
			$(function(){
				$('#maCarte').gmap3(
					{ 
						action: 'addMarker',
						latLng: [46.578498,2.457275],
						map:{
							center: true,
							zoom: 5,
							mapTypeId: google.maps.MapTypeId.TERRAIN
						},
						marker:{
							options:{
							draggable:true
							},
							events:{
								dragend: function(marker){
									$(this).gmap3(
										{
											action:'getAddress',
											latLng:marker.getPosition(),
											callback:function(results){
												var map = $(this).gmap3('get'),
													infowindow = $(this).gmap3({action:'get', name:'infowindow'}),
													content = results && results[1] ? results && results[1].formatted_address : 'Adresse inconnue';
												if (infowindow){
													infowindow.open(map, marker);
													infowindow.setContent(content);
												} else {
													$(this).gmap3({action:'addinfowindow', anchor:marker, options:{content: content}});
												}
											}
										}
									);
								}
							}
						}
					}
				);
			});
		</script>
	</head>
	
	<body>
		<div id="maCarte"></div>
	</body>
</html>

 

Source

getAddress

Résumé

GMap3 Plugin JQuery : getAddress

getAddress