简体   繁体   中英

How to convert waypoints into latitude and longitude?

var w = [], wp;
            var rleg = directionsDisplay.directions.routes[0].legs[0];
            data.start = {'lat': rleg.start_location.lat(), 'lng': rleg.start_location.lng()}
            data.end = {'lat': rleg.end_location.lat(), 'lng': rleg.end_location.lng()}


            var items = new Array();
            for (var i = 1; i <= textboxes; i++) {
                items[(i - 1)] = document.getElementById(i.toString()).value;
            }

            wp = document.getElementById('toAddress').value;
            if (items.length > 0) {
                w.push(wp)
            }



            for (var i = 0; i < items.length - 1; i++) {
                wp = items[i];
                if (wp !== "") {

                    w.push(wp);
                }
            }
            data.waypoints = w;

            var str = JSON.stringify(data)
            locationroot.value = str;
            return false;

Above code Output :

{"start":{"lat":22.3038548,"lng":70.80213219999996},"end":{"lat":22.470967,"lng":70.05772219999994},"waypoints":["jamnagar","kalavad"]}

but i want to output like this :

{"start":{"lat":22.3038548,"lng":70.80213219999996},"end":{"lat":22.470967,"lng":70.05772219999994},"waypoints":[[22.224905,70.62623409999992],[22.509108,70.22394120000001]]}

So how to convert waypoints location name into waypoints location latitude and longitude????

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