1

Google Geolocation はデータベースからの文字列を受け入れません

文字列にアドレスを手で入力すると機能します。

$city ="Karlstraße 33
36037 Fulda";
print_r (locate($city));

しかし、都市はデータベースからの文字列であり、機能しません。

$city =$obj->adresse;
    echo $city."</br>";
    $city = locate($city);

curl_exec($ch):
status" : "INVALID_REQUEST"

私はこれらの機能を使用します:

   function locate($string){
   $string = str_replace (" ","+",urlencode($string));//urlencode($string)
   $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $details_url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  // $response = json_decode(curl_exec($ch), true);
  echo curl_exec($ch);
//print_r($response);
   // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
   if ($response['status'] != 'OK') {
    return null;
   }
   //print_r($details_url);
   //print_r($response);
   $geometry = $response['results'][0]['geometry'];

    $longitude = $geometry['location']['lat'];
    $latitude = $geometry['location']['lng'];

    $array = array(
        'latitude' => $geometry['location']['lng'],
        'longitude' => $geometry['location']['lat'],
        'location_type' => $geometry['location_type'],
    );
    return $array;

}
4

0 に答える 0