簡體   English   中英

Laravel 5.5 Geocoder

[英]Laravel 5.5 Geocoder

我想在Laravel中使用這個包進行地理編碼。 我已將其添加到提供程序並發布配置,但我無法將其設置為工作。

    try {
        $location = Geocoder::geocode('68.145.37.34')->get();
        return $location;
    } catch (\Exception $e) {
        return $e;
    }

這將返回空對象。

我按原樣離開了配置文件。

return [
    'cache-duration' => 9999999,
    'providers' => [
        Chain::class => [
            GoogleMaps::class => [
                'en-US',
                env('GOOGLE_MAPS_API_KEY'),
            ],
            GeoPlugin::class  => [],
        ],
    ],
    'adapter'  => Client::class,
];

並為env添加了有效的API密鑰。 有什么我想念的嗎?

Geocoder導入use Geocoder\\Laravel\\Facades\\Geocoder;

編輯

如果有人遇到同樣的問題......這就是你從國家獲得這個國家的方式:

app('geocoder')->geocode('5.43.168.58')->get()->first()->getCountry()->getName();

在我看來,我不必要地復雜化,我要求在官方回購中更改文檔。

你嘗試在修補匠中使用dd()嗎? 我一直在嘗試......它對我有用..

試試這個 :

dd(app('geocoder')->geocode('68.145.37.34')->get());

回應:

    Illuminate\Support\Collection {#764
  items: array:1 [
    0 => Geocoder\Model\Address {#753
      -coordinates: Geocoder\Model\Coordinates {#755
        -latitude: 51.0823
        -longitude: -113.9578
      }
      -bounds: null
      -streetNumber: null
      -streetName: null
      -subLocality: null
      -locality: "Calgary"
      -postalCode: null
      -adminLevels: Geocoder\Model\AdminLevelCollection {#767
        -adminLevels: array:1 [
          1 => Geocoder\Model\AdminLevel {#768
            -level: 1
            -name: "Alberta"
            -code: "AB"
          }
        ]
      }
      -country: Geocoder\Model\Country {#769
        -name: "Canada"
        -code: "CA"
      }
      -timezone: null
      -providedBy: "geo_plugin"
    }
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM