Excelde Google Maps Verileri Kullanarak Mesafe ve Süre Hesaplama

Konudan anlaşılıyor ama test etmek lazım.

  • Excelde hiç data tutmadan tamamen Google maps verilerine göre mesafe hesaplayabiliyor.
  • İsimden  veya koordinat kullanarak hesaplama yapabiliyor. İsimde en yakın değeri kullanıyor.
  • Zaman saat cinsinden, uzaklık km cinsinden veriliyor.
  • feribotlar devre dışı bırakıldı. feribotları devreye almak için avoid=ferries ifadesini çıkarmak gerekiyorYolSure

KOD

Public Function MesafeHesapla(baslangic As String, bitis As String)
Dim firstVal As String, secondVal As String, lastVal As String
firstVal = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=”
secondVal = “&destinations=”
lastVal = “&mode=car&language=tr&sensor=false&avoid=ferries”
Set objHTTP = CreateObject(“MSXML2.ServerXMLHTTP”)
URL = firstVal & Replace(baslangic, ” “, “+”) & secondVal & Replace(bitis, ” “, “+”) & lastVal
objHTTP.Open “GET”, URL, False
objHTTP.setRequestHeader “User-Agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”
objHTTP.send (“”)
If InStr(objHTTP.responseText, “””distance”” : {“) = 0 Then GoTo ErrorHandl
Set regex = CreateObject(“VBScript.RegExp”): regex.Pattern = “””value””.*?([0-9]+)”: regex.Global = False
Set matches = regex.Execute(objHTTP.responseText)
tmpVal = Replace(matches(Index).SubMatches(0), “.”, Application.International(xlListSeparator))
MesafeHesapla = CDbl(tmpVal) / 1000
Exit Function
ErrorHandl:
MesafeHesapla = -1
End Function

Public Function SureHesapla(baslangic As String, bitis As String)
Dim firstVal As String, secondVal As String, lastVal As String
firstVal = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=”
secondVal = “&destinations=”
lastVal = “&mode=car&language=pl&sensor=false&avoid=ferries”
Set objHTTP = CreateObject(“MSXML2.ServerXMLHTTP”)
URL = firstVal & Replace(baslangic, ” “, “+”) & secondVal & Replace(bitis, ” “, “+”) & lastVal
objHTTP.Open “GET”, URL, False
objHTTP.setRequestHeader “User-Agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”
objHTTP.send (“”)
If InStr(objHTTP.responseText, “””duration”” : {“) = 0 Then GoTo ErrorHandl
Set regex = CreateObject(“VBScript.RegExp”): regex.Pattern = “duration(?:.|\n)*?””value””.*?([0-9]+)”: regex.Global = False
Set matches = regex.Execute(objHTTP.responseText)
tmpVal = Replace(matches(Index).SubMatches(0), “.”, Application.International(xlListSeparator))
SureHesapla = CDbl(tmpVal) / 3600
Exit Function
ErrorHandl:
SureHesapla = -1
End Function

 

2 thoughts on “Excelde Google Maps Verileri Kullanarak Mesafe ve Süre Hesaplama

  • Adil Karcilar
    20 Eylül 2016 at 06:31

    Çok faydalı ama ben yapamadım, daha detaylı yardımcı olurmusunuz.

  • Zekeriya
    23 Mart 2017 at 11:04

    Bende kodu excelde çalıştıramadım örnek excel koyabilir misiniz?

Bir cevap yazın

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>