简体   繁体   中英

How can I change the JavaScript code?

// Update the radius when the user makes a selection.
google.maps.event.addDomListener(document.getElementById('radius'),
    'change', function() {
       var meters = parseInt(this.value, 10);
       layer.setOptions({
         query: {
           select: locationColumn,
           from: tableId,
           where: 'ST_INTERSECTS(Latitude, ' +
               'CIRCLE(LATLNG(53.337638, -6.266971), ' + meters + '))'
          }
       });
       circle.setRadius(meters);
       //alert(position);
       //circle.setCenter(new google.maps.LatLng(position));
});

I want to change the (53.337638, -6.266971) to be a varible 'position', position has the same value type with (x,y), but it doesn't work with where: 'ST_INTERSECTS(Latitude, ' + 'CIRCLE(LATLNG('+position+'), ' + meters + '))' How can I modify the code ?

您可以分别指定position的两个属性,如下所示:

LATLNG(position.x, position.y)

A short solution is:

var position = [53.337638, -6.266971];
// irrelenant query code skipped
... + 'CIRCLE(LATLNG('+position[0]+','+position[1]+'), ' ...

A longer (but better semantically) solution would be to define an object with two properties, then overload its toString() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM