Adding country to Distance Matrix API

0

I'm using a function to return from google matrix api, the distance between two cities.

The problem is that when cities have names similar to those of North American cities, the distance calculation gives an error.

Is there a way to tell the API that the country is Brazil?

Here's the function:

  private function calculaDistancia () {

    $this->destino =  str_replace(" ","%20",$this->phpUtil->limpaCaracters($this->destino));

    $url = "http://maps.googleapis.com/maps/api/distancematrix/xml?Key=".$this->key."&origins=''".$this->origem."''|&destinations=''".$this->destino."''|&mode=''".$this->mode."''|&language=''".$this->language."''|&sensor=false
";

    $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;

  }

Here's the attempt with the city California-PR

Note: I've already tried

region = br country = br

Nothing works out.

    
asked by anonymous 04.11.2016 / 16:22

1 answer

0

I think I did.

Just add to the city its status.

$url = "http://maps.googleapis.com/maps/api/distancematrix/xml?Key=".$this->key."&origins=".$this->origem."-".$this->estadoOrigem."&destinations=".$this->destino."-".$this->estadoDestino."&mode=".$this->mode."&language=".$this->language."&sensor=false";   
    
04.11.2016 / 16:57