﻿loadJs("JavaScript/Point.js");

function showLocation2(adr1,toubu){
    GetPoint(adr1,function (location)
                        {
                            $("#"+toubu +"lon").val(location.lon);
                            $("#"+toubu +"lat").val(location.lat);
                            document.getElementById(''+toubu +'form').submit();
                        });
//      var geocoder, location1, location2, gDir;
//      geocoder = new GClientGeocoder();
//      gDir = new GDirections();
//      geocoder.getLocations(adr1, function(response){//去服务器查询
//           if (!response || response.Status.code != 200)
//                alert("对不起，没有找到此交叉路口！\n\n请检查输入是否正确！");
//           else
//           {
//                location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
//                //alert(adr1+"：" +location1.lon+"---"+location1.lat);
//                //return false;
//                $("#"+toubu +"lon").val(location1.lon);
//                $("#"+toubu +"lat").val(location1.lat);
//                document.getElementById(''+toubu +'form').submit();            
//           }
//      });
 }


function showLocation(adr1,adr2,i) {
      var geocoder, location1, location2, gDir;
      geocoder = new GClientGeocoder();
      gDir = new GDirections();
      //去服务器查询
      geocoder.getLocations(adr1, function (response) {
           if (!response || response.Status.code != 200)
           {
            alert("Sorry, we were unable to geocode the first address");
           }
           else
           {
                    location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                    geocoder.getLocations(adr2, function (response) {
                        if (!response || response.Status.code != 200)
                        {
                            alert("Sorry, we were unable to geocode the second address");
                        }
                        else
                        {
                        location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                        gDir.load('from: ' + location1.address + ' to: ' + location2.address);
                        //开始显示
                        GEvent.addListener(gDir, "load", function() {
                        var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
                        var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
                        document.getElementById('results'+i).innerHTML = '<strong>地址一: </strong>' + location1.address + ' (' + location1.lat + ':' + location1.lon + ')<br /><strong>地址二: </strong>' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles (or ' + drivingDistanceKilometers + ' kilometers)';
//                        alert( '<strong>地址一: </strong>' + location1.address + ' (' + location1.lat + ':' + location1.lon + ')<br /><strong>地址二: </strong>' + location2.address + ' (' + location2.lat + ':' + location2.lon + ')<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles + ' miles (or ' + drivingDistanceKilometers + ' kilometers)');
                        });
                        }

                    });
           }
      });
 }
 //测量步行距离
//var map;
//var gDire;
// function initialize(){
//    map = new GMap2(document.getElementById("map_canvas"));
//    gDire=new GDirections(map,document.getElementById("direDiv"));
//    GEvent.addListener(gDire, "load", function(){
//        var drivingDistanceKilometers = gDire.getDistance().meters;
//        alert(drivingDistanceKilometers);
//    });
//    GEvent.addListener(gDire, "error", function(){
//        alert(gDire.getStatus().code);
//    });
//}

