开发者

GLatLngBound from variables in javascript

I have images to overlay on google maps by using checkboxes. I made this script to not create the separate individual script for each overlay but it returns the error of proprty not supported in main.js of google maps api. However, i tried getting the output value in javascript alert and it returns the values as expected. Could anyone help please?

Here is the script.

function shImg(url,lat,lng) {
                var lat_ = "new GLatLng(" + lat + ")";
                var lng_ = "new GLatLng(" + lng + ")";
                var latlng = lat_ + ", " + lng_;
    开发者_Python百科            var ticked_ = document.getElementById(url);

                var boundaries_ = "new GLatLngBounds(" + latlng + ")";
                var imgurl_ = "http://www.mywebsite.com/" + url + ".jpg";
                imageOverlay_ = new GGroundOverlay(imgurl_, boundaries_);
                map.addOverlay(imageOverlay_);
    if (!ticked_.checked)   {
                map.clearOverlays();
            //  imageOverlay_=null;
    }
        else {
                                alert(boundaries_);
                imageOverlay_.show();

} }


The GLatLng constructor takes two arguments, a latitude and a longitude. Similarly GlatLngBounds takes two arguments, a GlatLng for the south west corner and one for the north east. See the api docs for more info.

Lastly why are you doing string concatenation all over the place? For example "new GLatLng(" + lat + ")"; should be new GLatLng(lat,lng);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜