Example of developing a map of Blackberry web bees: IP address query

Source: Internet
Author: User

You can query the geographical longitude and latitude coordinates of an IP address based on the IP address. For example, in the following example, the IP address 58.192.32.1 is located at 118.777802 and 32.061699, which is the location of Nanjing University.

[Java]
// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. rim;
// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. DigitalMap;
Import com. mapdigit. gis. MapPoint;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapType;
Import com. mapdigit. gis. service. IIpAddressGeocodingListener;
Import com. mapdigit. gis. service. IpAddressLocation;
Import com. pstreets. gisengine. demo. MapDemoRIM;
Import net. rim. device. api. ui. component. Menu;
Import net. rim. device. api. ui. MenuItem;
// [-------------------------------- Main class ----------------------------------]
Public class MapIpSearchRIM extends MapDemoRIM implements
IIpAddressGeocodingListener {
/**
* Entry point for application
* @ Param args Command line arguments (not used)
*/
Public static void main (String [] args)
{
// Create a new instance of the application and make the currently
// Running thread the application's event dispatch thread.
MapIpSearchRIM theApp = new MapIpSearchRIM ();
TheApp. enterEventDispatcher ();
}
Private MenuItem mapFindAddressMenuItem = new MenuItem ("Find Address", 0, 0 ){
Public void run (){
Map. getIpLocations ("58.192.32.1 ");
}
};
Public MapIpSearchRIM (){
Init ();
PushScreen (canvas );
Map. setIpAddressGeocodingListener (this );
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
Map. setCenter (center, 13, MapType. MICROSOFTCHINA );
}
Public void done (String query, IpAddressLocation result ){
If (result! = Null & result. error. length () = 0
& Result. longpolling. length ()> 0
& Result. latitude. 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 );
Map. panTo (mapPoint. point );
} Catch (Exception e ){
Result. error = "IP_NOT_FOUND ";
}
}
}
Protected void createMenu (Menu menu, int instance ){
Menu. add (mapFindAddressMenuItem );
}
}

// ----------------------------------- PACKAGE ------------------------------------
Package com. pstreets. gisengine. demo. rim;
// ------------------------------------- IMPORTS ------------------------------------
Import com. mapdigit. gis. DigitalMap;
Import com. mapdigit. gis. MapPoint;
Import com. mapdigit. gis. geometry. GeoLatLng;
Import com. mapdigit. gis. raster. MapType;
Import com. mapdigit. gis. service. IIpAddressGeocodingListener;
Import com. mapdigit. gis. service. IpAddressLocation;
Import com. pstreets. gisengine. demo. MapDemoRIM;
Import net. rim. device. api. ui. component. Menu;
Import net. rim. device. api. ui. MenuItem;
// [-------------------------------- Main class ----------------------------------]
Public class MapIpSearchRIM extends MapDemoRIM implements
IIpAddressGeocodingListener {
/**
* Entry point for application
* @ Param args Command line arguments (not used)
*/
Public static void main (String [] args)
{
// Create a new instance of the application and make the currently
// Running thread the application's event dispatch thread.
MapIpSearchRIM theApp = new MapIpSearchRIM ();
TheApp. enterEventDispatcher ();
}
Private MenuItem mapFindAddressMenuItem = new MenuItem ("Find Address", 0, 0 ){
Public void run (){
Map. getIpLocations ("58.192.32.1 ");
}
};
Public MapIpSearchRIM (){
Init ();
PushScreen (canvas );
Map. setIpAddressGeocodingListener (this );
GeoLatLng center = new GeoLatLng (32.0616667, 118.7777778 );
Map. setCenter (center, 13, MapType. MICROSOFTCHINA );
}
Public void done (String query, IpAddressLocation result ){
If (result! = Null & result. error. length () = 0
& Result. longpolling. length ()> 0
& Result. latitude. 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 );
Map. panTo (mapPoint. point );
} Catch (Exception e ){
Result. error = "IP_NOT_FOUND ";
}
}
}
Protected void createMenu (Menu menu, int instance ){
Menu. add (mapFindAddressMenuItem );
}
} Note: currently, IP address query results are always returned in English, as detailed in the preceding results.
ISP: "China Education and Research Network"
Organization: "Nan Jing University"
Country: "CN"
City: "Nanjing"
If you want to know the geographic name corresponding to the longitude and latitude, you can use the address anti-encoding service.
You can enter 127.0.0.1 to query the local address.

 

Author: mapdigit

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.