0

Google 距離マトリックスは、最大 100 個のパラメーターを受け入れることができます。しかし、GET Ruquest url lenth では 15 未満 (2048 文字だと思います) に制限されており、エラー 414 - 要求された URL が大きすぎて処理できません。したがって、POST メソッドを使用する必要があるという結論に達しました。しかし、私はできません。REQUEST_DENIED エラーが発生しました。では、どうすればこのサービスを利用できますか?

    public static bool GetMatrix(string origins, string destinations)
    {
        string poststring = string.Format("origins={0}&destinations={1}&mode=bicycling&language=fr-FR&sensor=false", origins, destinations);
        byte[] postdata = Encoding.UTF8.GetBytes(poststring);

        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://maps.googleapis.com/maps/api/distancematrix/xml");
        webRequest.Method = "POST";
        webRequest.ContentType = "application/xml"; // or any other type dont work
        webRequest.ContentLength = postdata.Length;
        using (Stream writer = webRequest.GetRequestStream())
            writer.Write(postdata, 0, postdata.Length);

        using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
        {
            //Only for debug
            using (var stream = new StreamReader(webResponse.GetResponseStream()))
                System.Diagnostics.Debug.WriteLine(stream.ReadToEnd());

            return (webResponse.StatusCode == HttpStatusCode.OK);
        }
    }
4

1 に答える 1

1

JSメソッド

例えば。距離行列の例

var origin1 = new google.maps.LatLng(55.930385, -3.118425);
var origin2 = "Greenwich, England";
var destinationA = "Stockholm, Sweden";
var destinationB = new google.maps.LatLng(50.087692, 14.421150);

var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
  {
    origins: [origin1, origin2],
    destinations: [destinationA, destinationB],
    travelMode: google.maps.TravelMode.DRIVING,
    avoidHighways: false,
    avoidTolls: false
  }, callback);

function callback(response, status) {
  // See Parsing the Results for
  // the basics of a callback function.
}

google.comなしで距離を計算するC#メソッド

 public decimal calcDistance(decimal latA, decimal longA, decimal latB, decimal longB)
    {

        double theDistance = (Math.Sin(DegreesToRadians(latA)) *
                Math.Sin(DegreesToRadians(latB)) +
                Math.Cos(DegreesToRadians(latA)) *
                Math.Cos(DegreesToRadians(latB)) *
                Math.Cos(DegreesToRadians(longA - longB)));

        return Convert.ToDecimal((RadiansToDegrees(Math.Acos(theDistance)))) * 69.09M * 1.6093M;
    }
于 2012-11-19T12:19:36.687 に答える