In Android, instances are queried by IP addresses, and android obtains the longitude and latitude.

Source: Internet
Author: User

In Android, instances are queried by IP addresses, and android obtains the longitude and latitude.
In Android, an instance is used to query the longitude and latitude coordinates of an IP address.

As you all know, you can know the specific location of an IP address. In Android, you can also get its location from the IP address, that is, the specific geographical longitude and latitude coordinates.

This article describes how to query the geographical longitude and latitude coordinates based on the IP address. The following example shows how to query the coordinates of the IP address's longitude and latitude (118.777802, 32.061699 ).

Java code
  1. Package eoe. demo;
  2. Import com. mapdigit. gis. DigitalMap;
  3. Import com. mapdigit. gis. MapPoint;
  4. Import com. mapdigit. gis. geometry. GeoLatLng;
  5. Import com. mapdigit. gis. service. IIpAddressGeocodingListener;
  6. Import com. mapdigit. gis. service. IpAddressLocation;
  7. Import com. pstreets. gisengine. R;
  8. Import com. pstreets. gisengine. SharedMapInstance;
  9. Import android. app. Activity;
  10. Import android. OS. Bundle;
  11. Import android. view. Menu;
  12. Import android. view. MenuInflater;
  13. Import android. view. MenuItem;
  14. Public class MapIpSearch extends Activity implements
  15. IIpAddressGeocodingListener {
  16. @ Override
  17. Public void onCreate (Bundle savedInstanceState ){
  18. Super. onCreate (savedInstanceState );
  19. SetContentView (R. layout. main );
  20. }
  21. @ Override
  22. Public void onStart (){
  23. Super. onStart ();
  24. GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
  25. SharedMapInstance. map. setCenter (center, 15,
  26. Com. mapdigit. gis. raster. MapType. MICROSOFTCHINA );
  27. SharedMapInstance. map. setIpAddressGeocodingListener (this );
  28. }
  29. @ Override
  30. Public boolean onCreateOptionsMenu (Menu menu ){
  31. MenuInflater inflater = getMenuInflater ();
  32. Inflater. inflate (R. menu. mapgeocoding_menu, menu );
  33. Return true;
  34. }
  35. @ Override
  36. Public boolean onOptionsItemSelected (MenuItem item ){
  37. Switch (item. getItemId ()){
  38. Case R. id. findaddress:
  39. SharedMapInstance. map. getIpLocations ("58.192.32.1 ");
  40. Return true;
  41. Default:
  42. Return super. onOptionsItemSelected (item );
  43. }
  44. }
  45. @ Override
  46. Public void done (String query, IpAddressLocation result ){
  47. If (result! = Null & result. error. length () = 0
  48. & Result. longpolling. length ()> 0
  49. & Result. longpolling. length ()> 0 ){
  50. Try {
  51. MapPoint mapPoint = new MapPoint ();
  52. String latLng = "[" + result. longpolling + "," + result. latitude + ", 0]";
  53. MapPoint. point = DigitalMap. fromStringToLatLng (latLng );
  54. MapPoint. setName (result. organization );
  55. MapPoint. setNote (result. city + "" + result. country );
  56. SharedMapInstance. map. panTo (mapPoint. point );
  57. } Catch (Exception e ){
  58. Result. error = "IP_NOT_FOUND ";
  59. }
  60. }
  61. }
  62. @ Override
  63. Public void readProgress (int bytes, int total ){
  64. }
  65. }

 


It is a pity that I cannot query the actual longitude and latitude Based on the IP address. Sometimes, IP addresses are dynamically allocated. IP addresses in a city or province are not fixed in a region. For example, home ADSL is the most typical dynamic IP Address allocation. The IP address you will use later may be allocated to others after you shut down, therefore, the corresponding longitude and latitude cannot be determined directly. However, there is a situation that can be determined, that is, this person uses a fixed IP address. In fact, if you want to find the specific IP address, you can call the service provider in Chongqing to ask them to tell you which user occupies the IP address at this moment, the endpoint of his registration is somewhere, but you also need to know that the service provider will not disclose the customer's registration information to you because they have relevant privacy protection terms.
To sum up, you cannot find ......
Change the method.
Query the longitude and latitude http://dir.twseo.org/ip-check.php in which the IP is used by IP. Hope to adopt it.

Related Article

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.