0

I wonder whether someone may be able to help me please.

This page allows users to filter (via checkboxes), markers which are placed on the map. Clicking on any marker performs a 'reverse geocode' action and in conjunction with selecting the 'Search Locations' button, the user can then see POI's within a given radius of the clicked marker.

For demo purposes, if you select the 'Coin' checkbox, click the green marker, then select the 'Search Locations' button, the marker will bounce and the right hand sidebar will be populated with POI's.

The problem I'm having is that in Internet Explorer everything works fine, but when I try to run this in Chrome, the marker looses the 'bounce' functionality, the 'reverse geocode' doesn't run and in the error console I receive the following error:

Uncaught ReferenceError: reversegeocode is not defined at line 55 of my code which is: reversegeocode(); I've done some reading on this and other sites and from reading the guidance I've tried changing this part of my code to this:

function geocodePosition(pos) {
    var clickListener =
    document.getElementById('findosgb36lat').value = this.mylat;
    document.getElementById('findosgb36lon').value = this.mylon;
    document.getElementById('address').value = this.myaddress;
    if(bouncingMarker) 
        bouncingMarker.setAnimation(null); 
        if(bouncingMarker != this) { 
            this.setAnimation(google.maps.Animation.BOUNCE); 
            bouncingMarker = this; 
        }
        else bouncingMarker = null; 
    }

    geocoder.geocode({latLng: pos }, function(responses) {
        if (responses && responses.length > 0) {
            updateMarkerAddress(responses[0].formatted_address);
        } else {
            updateMarkerAddress('Cannot determine address at this location.');
        }
    });
}

function updateMarkerAddress(str) {
    document.getElementById('address').value = str;
}

function getAddress(latlng) {
    if (!geocoder) {
        geocoder = new google.maps.Geocoder();
    }

    geocoder.geocode({ 'latLng': latlng }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            // Looping through the result
            for (var i = 0; i < results.length; i++) {
                if (results[0].formatted_address) {
                    document.getElementById('address').value = 
                        results[0].formatted_address;
                } 
            }
        }
    }
)
}

But unfortunately, this doesn't work and actually creates more problems with syntax errors.

I'm relatively new to Javascript, so perhaps I've totally misunderstood,. But I just wondered whether someone could possibly take a look at this please and let me know where I'm going wrong?

Many thanks and kind regards

4

1 回答 1

1

代码反馈:

  • 您的代码中的第二行是什么:var clickListener =打算做什么(缺少某些东西)?
  • 您两次调用都geocoder.geocode传递了一个具有名为的属性的对象:latLng; 传递的对象应与google.maps.GeocoderRequestapi-doc的结构相匹配,该结构具有名为:addressboundslocationregion. 我建议您将这些属性的名称从:latLng更改为location.
  • 我不确定所显示代码的上下文,但this在此代码部分中的用法看起来很可疑:

    if(bouncingMarker != this) { 
        this.setAnimation(google.maps.Animation.BOUNCE); 
        bouncingMarker = this; 
    }

看起来你在一个全局函数中,所以看起来在this这里使用可能没有意义?

这就是我在第一次通过后看到的全部内容;希望这可以帮助你 -

于 2012-05-31T11:15:27.713 回答