2

Handler私の目にはほぼ同じであるが、一方は正しく返され、もう一方は返されないという2つのインスタンスがあるので、コードに何か問題があるのではないかと思います。主な活動では、次のように呼ばれます。

働く

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);
    }

}

動作していないURLを確認しましたがHandler、データは正しく返されます。実際、私は他の場所で同じURLを使用しており、正常に機能しています。足りないものはありますか?

4

0 に答える 0