Javascript-how do I convert an IP address to a coordinate of longitude and latitude?

Source: Internet
Author: User
Tags geoip geoip database
Recently, we are working on map-related applications. A large amount of user data is an IP address. If you mark a user on a map, you need to convert the IP address to the longitude and latitude coordinates. Is there any feasible way to achieve this? Recently, we are working on map-related applications.
A large amount of user data is an IP address. If you mark a user on a map, you need to convert the IP address to the longitude and latitude coordinates.
Is there any feasible way to achieve this?

Reply content:

Recently, we are working on map-related applications.
A large amount of user data is an IP address. If you mark a user on a map, you need to convert the IP address to the longitude and latitude coordinates.
Is there any feasible way to achieve this?

I have done a similar thing, and the solutions I use are rather difficult:

  • Nginx has a geoip module. Check whether the installed Nginx has compiled this module.
nginx -Vnginx version: nginx/1.1.19TLS SNI support enabledconfigure 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

If you have not re-compiled an Nginx with geoip module.

  • The Nginx configuration file is used to configure the geoip database. The geoip database is charged and downloaded for free. I will use it for free and update it frequently.
http {        geoip_country  /etc/nginx/GeoIP.dat;        geoip_city     /etc/nginx/GeoLiteCity.dat;}
  • The GEO information can be passed to the application through the fastcgi parameter. The following is a fastcgi configuration example of Django.
#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 passes the obtained longitude and latitude to the foreground through Ajax and submits it to the Google Map API for display. If it is an IP address in China, it may not be accurate. I use a database with pure IP addresses. There are many Google methods.

The limitation of this method is to use Nginx + fastcgi, not suitable for everyone.

Meaningless. The IP address is converted to the city information. The longitude and latitude of city information is the central point of regional administrative planning.

I also have the idea of querying sites by IP location.

Looked up, http://www.iplocationtools.com/this API looks more reliable.
This website http://www.ipgeo.com/also claims to provide API, but the API domain name can not be resolved.
SAE also provides paid interfaces.

See if this has helped https://developers.google.com/maps/do...

Http://freegeoip.net/static/index.htm...
Return JSONP data.

Http://www.haoservice.com/docs/8 here is the latitude and longitude data interface, according to provide coordinates and other query location

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.