定制 survos/geoapify-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

survos/geoapify-bundle

最新稳定版本:2.0.96

Composer 安装命令:

composer require survos/geoapify-bundle

包简介

Symfony bundle to interact with https://www.geoapify.com/

README 文档

README

Symfony Bundle to access the API at https://www.geoapify.com/

The geoapify website offers 3000 free lookups per day, and it's very fast and easy to register for an API key. The main purpose of this bundle is to simplify storing the API key in an environment variable and to cache the responses.

First, get an API key at https://myprojects.geoapify.com/projects and add it to .env.local

echo "GEOAPIFY_API_KEY=my-api-key" >> .env.local
composer req survos/geoapify-bundle
bin/console debug:config survos_geoapify --format=yaml > config/packages/survos_geoapify.yaml
# config/packages/survos_geoapify.yaml
survos_geoapify:
  api_key: '%env(GEOAPIFY_API_KEY)%'

Trivial but functional application

Requirements:

  • Locally installed PHP 8
  • Symfony CLI
  • sed (to change /app to / without opening an editor)
  • API Key
symfony new GeoapifyDemo --webapp && cd GeoapifyDemo
echo "GEOAPIFY_API_KEY=my-api-key" >> .env.local
symfony composer req survos/geoapify-bundle
symfony console make:controller AppController
sed -i "s|/app|/|" src/Controller/AppController.php 

cat <<'EOF' > templates/app/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
{% set ip = app.request.clientIp %}
{{ isLocalhost(ip) ? "<div>Localhost has no geolocation, using value from config</div>" }}
Hello, visitor from {{ ipGeolocation(ip).country_name}} )
<pre>{{ ipGeolocation(ip)|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>

Powered by Geoapify.com <a href="https://www.geoapify.com">IP geolocation</a> web service.

{% endblock %}
EOF

symfony server:start -d
symfony open:local

Notes

https://freeipapi.com/ is a free service that can be used without an API key (up to 60 requests per minute).

统计信息

  • 总下载量: 1.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-12