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
- Package eoe. demo;
- Import com. mapdigit. gis. DigitalMap;
- Import com. mapdigit. gis. MapPoint;
- Import com. mapdigit. gis. geometry. GeoLatLng;
- Import com. mapdigit. gis. service. IIpAddressGeocodingListener;
- Import com. mapdigit. gis. service. IpAddressLocation;
- Import com. pstreets. gisengine. R;
- Import com. pstreets. gisengine. SharedMapInstance;
- Import android. app. Activity;
- Import android. OS. Bundle;
- Import android. view. Menu;
- Import android. view. MenuInflater;
- Import android. view. MenuItem;
- Public class MapIpSearch extends Activity implements
- IIpAddressGeocodingListener {
- @ Override
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. main );
- }
- @ Override
- Public void onStart (){
- Super. onStart ();
- GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
- SharedMapInstance. map. setCenter (center, 15,
- Com. mapdigit. gis. raster. MapType. MICROSOFTCHINA );
- SharedMapInstance. map. setIpAddressGeocodingListener (this );
- }
- @ Override
- Public boolean onCreateOptionsMenu (Menu menu ){
- MenuInflater inflater = getMenuInflater ();
- Inflater. inflate (R. menu. mapgeocoding_menu, menu );
- Return true;
- }
- @ Override
- Public boolean onOptionsItemSelected (MenuItem item ){
- Switch (item. getItemId ()){
- Case R. id. findaddress:
- SharedMapInstance. map. getIpLocations ("58.192.32.1 ");
- Return true;
- Default:
- Return super. onOptionsItemSelected (item );
- }
- }
- @ Override
- Public void done (String query, IpAddressLocation result ){
- If (result! = Null & result. error. length () = 0
- & Result. longpolling. length ()> 0
- & Result. longpolling. length ()> 0 ){
- Try {
- MapPoint mapPoint = new MapPoint ();
- String latLng = "[" + result. longpolling + "," + result. latitude + ", 0]";
- MapPoint. point = DigitalMap. fromStringToLatLng (latLng );
- MapPoint. setName (result. organization );
- MapPoint. setNote (result. city + "" + result. country );
- SharedMapInstance. map. panTo (mapPoint. point );
- } Catch (Exception e ){
- Result. error = "IP_NOT_FOUND ";
- }
- }
- }
- @ Override
- Public void readProgress (int bytes, int total ){
- }
- }
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.