我想知道我的代码是否有问题,因为我有两个 a 实例Handler
,从我的角度来看,它们几乎相同,但一个正确返回,另一个没有。在主要活动中,它们的调用如下:
在职的
BingSpatialDataService bsds = new BingSpatialDataService(Constants.BingSpatialAccessId,
Constants.BingSpatialSourceName,
Constants.BingSpatialEntityTypeName,
Constants.BingSpatialQueryKey);
bsds.FindByAreaCompleted = new Handler()
{
public void handleMessage(Message msg)
{
if(msg.obj != null)
{
// Do something with msg
}
}
};
bsds.FindByArea(l.Point, searchRadius, null);
不工作
FWSDataService fds = new FWSDataService();
fds.FindByTimespanCompleted = new Handler()
{
public void handleMessage(Message msg)
{
if(msg.obj != null)
{
// Do something with msg
}
}
};
fds.FindByTimespan(timespan);
fds
并且bsds
是包含处理程序代码的类
bsds
public class BingSpatialDataService {
public Handler FindByAreaCompleted;
public Handler FindByIDCompleted;
public Handler FindByPropertyCompleted;
private String _queryKey;
private String _serviceURL;
public BingSpatialDataService(String accessId, String dataSourceName, String entityTypeName, String queryKey){
_queryKey = queryKey;
_serviceURL = "http://spatial.virtualearth.net/REST/v1/data/" + accessId + "/" + dataSourceName + "/" + entityTypeName;
}
/* Public Methods */
//http://spatial.virtualearth.net/REST/v1/data/accessId/dataSourceName/entityTypeName?spatialFilter=nearby(latitude,longitude,distance)&queryoption1&queryoption2&queryoptionN&key=queryKey
public void FindByArea(Coordinate center, double distance, QueryOption options){
StringBuilder sb = new StringBuilder();
sb.append(_serviceURL);
//Add spatial filter
sb.append("?spatialFilter=nearby(");
sb.append(center.Latitude);
sb.append(",");
sb.append(center.Longitude);
sb.append(",");
sb.append(distance);
sb.append(")");
//Add Query Options
if(options != null){
sb.append(options.toString());
}else{
sb.append("&$format=json");
}
//Add Bing Maps Key
sb.append("&key=");
sb.append(_queryKey);
//create service request
ServiceRequest request = new ServiceRequest(sb.toString(), RequestType.GET, ContentTypes.JSON);
QueryServiceAsyncTask service = new QueryServiceAsyncTask(FindByAreaCompleted);
service.execute(request);
}
//http://spatial.virtualearth.net/REST/v1/data/accessId/dataSourceName/entityTypeName?spatialFilter=bbox(southLatitude,westLongitude,northLatitude,eastLongitude)&queryOption1&queryOption2&queryOptionN)&key=queryKey
public void FindByArea(LocationRect boundingBox, QueryOption options){
StringBuilder sb = new StringBuilder();
sb.append(_serviceURL);
//Add spatial filter
sb.append("?spatialFilter=bbox(");
sb.append(boundingBox.getSouth());
sb.append(",");
sb.append(boundingBox.getWest());
sb.append(",");
sb.append(boundingBox.getNorth());
sb.append(",");
sb.append(boundingBox.getEast());
sb.append(")");
//Add Query Options
if(options != null){
sb.append(options.toString());
}else{
sb.append("&$format=json");
}
//Add Bing Maps Key
sb.append("&key=");
sb.append(_queryKey);
//create service request
ServiceRequest request = new ServiceRequest(sb.toString(), RequestType.GET, ContentTypes.JSON);
QueryServiceAsyncTask service = new QueryServiceAsyncTask(FindByAreaCompleted);
service.execute(request);
}
fds
public class FWSDataService {
public Handler FindByTimespanCompleted;
private String serviceURL;
public FWSDataService()
{
serviceURL = "http://10.90.32.120/fws/home/getsiterecentrainfall/?regionid=1&regionid=19&";
}
public void FindByTimespan(int timespan)
{
StringBuilder sBuilder = new StringBuilder();
sBuilder.append(serviceURL);
// Add timespan filter
sBuilder.append("timespan=");
sBuilder.append(timespan);
ServiceRequest request = new ServiceRequest(sBuilder.toString(), RequestType.GET, ContentTypes.JSON);
QueryServiceAsyncTask service = new QueryServiceAsyncTask(this.FindByTimespanCompleted);
service.execute(request);
}
}
我已经检查了Handler
那个不起作用的 URL,并且数据被正确返回。事实上,我在其他地方使用了相同的 URL,它运行良好。有什么我想念的吗?