亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

最近,在做地圖相關的應用,請問有沒有可行的辦法實現?

最近,在做地圖相關的應用,請問有沒有可行的辦法實現?

繁花如伊 2023-04-14 18:14:26
有大量的用戶數據是ip地址,如果把用戶標記在地圖上,需要把ip地址轉換為經緯度坐標。
查看完整描述

2 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

無意義。ip地址轉換過來是城市信息。城市信息得到的經緯度是地區行政規劃中心點。

查看完整回答
反對 回復 2023-04-17
?
慕的地6264312

TA貢獻1817條經驗 獲得超6個贊

我曾經做過一個類似的事情,使用的方案比較折騰:

  • Nginx 有 geoip 的模塊,檢查安裝的 Nginx 是否編譯了這個模塊。

nginx -V

nginx version: nginx/1.1.19TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module

如果是沒有重新編譯一個帶 geoip 模塊的 Nginx 使用。

  • Nginx 的配置文件配置 geoip 的數據庫,geoip 的數據庫有收費的,也有免費的下載,我都是用免費的,經常更新一下即可。

http {
        geoip_country  /etc/nginx/GeoIP.dat;
        geoip_city     /etc/nginx/GeoLiteCity.dat;
}
  • GEO 的信息就可以通過fastcgi的參數傳遞給應用了,以下是Django的一段 fastcgi 配置示例。

#GeoIPfastcgi_param GEOIP_COUNTRY_CODE $geoip_city_country_code;fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;fastcgi_param GEOIP_REGION $geoip_region;fastcgi_param GEOIP_CITY $geoip_city;fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;fastcgi_param GEOIP_LAT $geoip_latitude;fastcgi_param GEOIP_LNG $geoip_longitude;
  • Django 把得到的經緯度通過 Ajax 傳遞到前臺,交給 Google Map API 顯示即可。如果是國內的 IP 可能就不準確,我用了純真IP的數據庫,方法 Google 一下有很多。

這個方法的限定是使用 Nginx + fastcgi,不是適合所有的人。


查看完整回答
反對 回復 2023-04-17
  • 2 回答
  • 0 關注
  • 280 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號