Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌在监听器中映射地理代码_Javascript_Google Maps - Fatal编程技术网

Javascript 谷歌在监听器中映射地理代码

Javascript 谷歌在监听器中映射地理代码,javascript,google-maps,Javascript,Google Maps,我不知道为什么r1变量没有定义。 'latLng':mEvent.latLng在其他功能上工作正常 <!-- API V3 --> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 变量r1很可能未定义,因为它超出范围。你需要把它的声明提高一点。例如: google.maps.event.addListener(map,

我不知道为什么r1变量没有定义。 'latLng':mEvent.latLng在其他功能上工作正常

<!-- API V3 --> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

变量r1很可能未定义,因为它超出范围。你需要把它的声明提高一点。例如:

google.maps.event.addListener(map, 'click', function(mEvent) {

        var geo1 = new google.maps.Geocoder();
        var r1;
        geo1.geocode( { 'latLng': mEvent.latLng }, function(results, status) {
            if ( status == google.maps.GeocoderStatus.OK )
            {
                r1 = results[0].formatted_address;
            }
            else
            {
                r1 = '?';
            }
        });

        //do things with mEvent.latLng and r1...

如果您仍然发现一些问题,请使用Firebug(在Firefox中)或其他浏览器中的内置调试器。当调试器处于活动状态时,可以插入“debugger;”关键字以在某一行停止。然后,您将能够检查哪些变量可用。

变量r1很可能未定义,因为它超出范围。你需要把它的声明提高一点。例如:

google.maps.event.addListener(map, 'click', function(mEvent) {

        var geo1 = new google.maps.Geocoder();
        var r1;
        geo1.geocode( { 'latLng': mEvent.latLng }, function(results, status) {
            if ( status == google.maps.GeocoderStatus.OK )
            {
                r1 = results[0].formatted_address;
            }
            else
            {
                r1 = '?';
            }
        });

        //do things with mEvent.latLng and r1...

如果您仍然发现一些问题,请使用Firebug(在Firefox中)或其他浏览器中的内置调试器。当调试器处于活动状态时,可以插入“debugger;”关键字以在某一行停止。然后,您将能够检查哪些变量可用。

在分配给
r1
之前,
结果的值是多少?您可以控制台.log吗?
结果在分配给
r1
之前的值是多少?你能用console.log吗?