Afstand uitrekenen

Gestart doorJustafool4 reacties25 weergaven

5 berichten · pagina 1 van 1

Justafool

Lid · Topicstarter

Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Geen idee of jullie er wat aan hebben of dat het makkelijker kan of weet ik veel wat yummie
Met deze functie kan je in ieder geval de afstand berekenen tussen adressen/postcodes etc.

ik moet hem nog beter maken dat hij ook controleert naar status etc.. maar dat komt snel.

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] GetDistance[COLOR= #007700]([/COLOR][COLOR= #0000BB]$origin[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$destination[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$tran[/COLOR][COLOR= #007700]) {[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$tran[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]driving[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700]=[/COLOR] simplexml_load_file[COLOR= #007700]([/COLOR][COLOR= #DD0000]http://maps.googleapis.com/maps/api/directions/xml?origin=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$origin[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&destination=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$destination[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&mode=driving&sensor=false[/COLOR][COLOR= #007700]);
        
    }[/COLOR]
    [URL="http://www.php.net/elseif"]elseif[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$tran[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]walking[/COLOR][COLOR= #007700]) {[/COLOR]

        [COLOR= #0000BB]$map[/COLOR] [COLOR= #007700]=[/COLOR] simplexml_load_file[COLOR= #007700]([/COLOR][COLOR= #DD0000]http://maps.googleapis.com/maps/api/directions/xml?origin=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$origin[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&destination=[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$destination[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]&mode=walking&sensor=false[/COLOR][COLOR= #007700]);

    }[/COLOR]

    [COLOR= #0000BB]$dis[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$map[/COLOR][COLOR= #007700]->[/COLOR]children[COLOR= #007700]() as[/COLOR] [COLOR= #0000BB]$child[/COLOR][COLOR= #007700]) {[/COLOR]
        
        [COLOR= #0000BB]$dis[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #0000BB]$child[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    [COLOR= #0000BB]$status[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$dis[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]];[/COLOR]
    
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$status[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]OK[/COLOR][COLOR= #007700]) {[/COLOR]
        
        [COLOR= #0000BB]$distance[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$dis[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]]->[/COLOR]leg[COLOR= #007700]->[/COLOR]distance[COLOR= #007700]->[/COLOR]text[COLOR= #007700];[/COLOR]
        
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$distance[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    
        [COLOR= #0000BB]$error[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]Error try again[/COLOR][COLOR= #007700];[/COLOR]
        [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$error[/COLOR][COLOR= #007700];
        
    }

    
}[/COLOR]

[COLOR= #FF8000]//driving[/COLOR]
[COLOR= #0000BB]$distance[/COLOR] [COLOR= #007700]=[/COLOR] GetDistance[COLOR= #007700]([/COLOR][COLOR= #DD0000]9628ET[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]6841 HN[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]driving[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$distance[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];[/COLOR]
    
[COLOR= #FF8000]//walking[/COLOR]
[COLOR= #0000BB]$distance[/COLOR] [COLOR= #007700]=[/COLOR] GetDistance[COLOR= #007700]([/COLOR][COLOR= #DD0000]9628ET[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]6841HN[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]walking[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$distance[/COLOR][COLOR= #007700];[/COLOR]
    
?>
0
Berichten
18.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoe moet die postcode opgesteld zijn?
1234AB of wat?
0
Justafool

Lid · Topicstarter

Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Luukvdo schreef:
Hoe moet die postcode opgesteld zijn?
1234AB of wat?
Maakt niet uit volgens mij.. gaat via google maps dus alles wat google maps kan moet deze ook kunnen..

net getest met adressen werkt ook..
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Je moet er wel "1234AB, Nederland" van maken, anders pakt ie andere dingen.
0
Justafool

Lid · Topicstarter

Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lennard schreef:
Je moet er wel "1234AB, Nederland" van maken, anders pakt ie andere dingen.
Ja dat kan kloppen, heb er zelf nog geen probelemen mee gehad na een aantal tests.. maar voor zekerheid kan je dat doen ja..
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren