編輯:關於Android編程
IP地址查詢,可以根據IP地址查詢到該IP所在的地理經緯度坐標,比如下述例子查詢IP 地址58.192.32.1,所在經緯度為118.777802,32.061699,為南京大學所在地。
[java]
package com.pstreets.gisengine.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) {
// Handle item selection
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.longitude.length() > 0
&& result.longitude.length() > 0) {
try {
MapPoint mapPoint = new MapPoint();
String latLng = "[" + result.longitude + "," + 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) {
}
}
package com.pstreets.gisengine.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) {
// Handle item selection
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.longitude.length() > 0
&& result.longitude.length() > 0) {
try {
MapPoint mapPoint = new MapPoint();
String latLng = "[" + result.longitude + "," + 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) {
}
}
注:目前IP查詢結果總是以英文返回,如上述結果詳細內容。
ISP:”China Education and Research Network”
Organization: “Nan Jing University”
Country: “CN”
City: “Nanjing”
若想知道該經緯度對應的地名,可以使用地址反編碼服務。
你可以輸入 127.0.0.1 查詢本機地址。
作者:mapdigit
前言最近Android studio(下文簡稱AS)官方發布了正式版,目前火得不行。個人認為主要是因為android是google自家的產品,AS也是他自己搞的IDE,以
這次是一個時鐘類應用,目前依舊是主要的功能,長得還是很挫。當然了,核心功能是有的……鬧鐘之前的准備布局的話,不管是采用FrameLayout或
MainActivity:package com.ruru.dialogproject; import android.app.Activity; import andr
前言最近公司項目有一個錄音的錄制和播放動畫需求,然後時間是那麼緊,那麼趕緊開撸。先看效果圖嗯,然後大致就是這樣,按住錄音,然後有一個倒計時,最外層一個進度條,還有一個類似