Carlos Rocha Posted November 17, 2016 at 09:19 PM Report #600638 Posted November 17, 2016 at 09:19 PM Estou usando o seguinte método para calcular a distancia entre 2 cidades usando Google API Matrix: private function calculaDistancia () { $this->destino = str_replace(" ","%20",$this->phpUtil->limpaCaracters($this->destino)); $url = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=".$this->origem."-".$this->estadoOrigem."&destinations=".$this->destino."-".$this->estadoDestino."&mode=".$this->mode."&language=".$this->language."&sensor=false"; print $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($ch); $freteXML = simplexml_load_string($data); $distancia = $freteXML->row->element->distance->value; return $distancia; } De fato funciona. E a url de pesquisa é: $url = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=".$this->origem."-".$this->estadoOrigem."&destinations=".$this->destino."-".$this->estadoDestino."&mode=".$this->mode."&language=".$this->language; Bom, o problema é que em uma consulta tive a seguinte url de entrada: https://maps.googleapis.com/maps/api/distancematrix/xml?origins=Muriae-MG&destinations=Macapá-AP&mode=driving&language=pt-BR&sensor=false Que retornou o seguinte: <DistanceMatrixResponse> <status>OK</status> <origin_address>Muriaé, MG, Brasil</origin_address> <destination_address>Macapá, AP, Brasil</destination_address> <row> <element> <status>ZERO_RESULTS</status> </element> </row> </DistanceMatrixResponse> Note que ele identifica as cidades mas não consegue calcular as disâncias. Algum recurso?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now