Bonjour à tous,

Etant plus habitué à python j'apprend js pour utiliser l'api google map.

Mais je n'arrive pas à faire un "return" et cela fait un moment que je cherche.

Sauriez vous pourquoi pour le code suivant,
Dans la fonction adress2latlng j'ai une une valeur pour latlng_local que je n’arrive pas à récupérer dans initialize ?

Merci de votre aide

Alex

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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
 
 
    function initialize() {
    var latlng_center=adress2latlng("paris,France");
    alert("dans initialize : "+latlng_center)
    }
 
    function adress2latlng(address) {
        var geocoder;
        geocoder = new google.maps.Geocoder();
        geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var latlng_local = results[0].geometry.location;
            alert("dans adress2latlng "+address+" latlng "+latlng_local);
            return latlng_local;
        } else {
          alert("Geocode was not successful for the following reason: " + status);
        }
        });
    }
 
 
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>