How to properly build HTTP connection suffix
I have written code to get a location name using Google Maps reverse geocoding, for example:
http://maps.google.com/maps/geo?json&ll=9.6,73.7
How can I add an appropriate HTTP connection suffix to the above URL?
I have tried the following function:
private static String getConnectionStringForGoogleMap(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
connectionString="&interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
connectionString = "&deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
String carrierUid=getCarrierBIBSUid();
if(carrierUid == null) {
connectionString = "&deviceside=true";
}
else{
connectionString = "&deviceside=false&connectionUID="+carrierUid + "&ConnectionType=mds-public";
}
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
}
return connectionString;
}
When I run the application in the simulator, I create the URL like this:
http://ma开发者_如何学编程ps.google.com/maps/geo?json&ll=9.6,73.7+getConnectionStringForGoogleMap();
But I get a tunnel exception and am not sure what to do next.
This URL also leads to an exception:
http://maps.google.com/maps/geo?json&ll=9.6,73.7&deviceside=false&ConnectionType=mds-public
As does:
http://maps.google.com/maps/geo?json&ll=9.6,73.7;deviceside=false;ConnectionType=mds-public
I am confused about what to do to get this to work.
You definitely want semi-colons (;) and not ampersands (&). Are you tring to run this on the simulator? If so, do you have the MDS simulator running? That is required in order to use devicside=false
on the simulator.
Try using Versatile Monkey's networking helper class to find the best path for your HTTP connection and avoid those tunnel exceptions. And form the URL with the correct syntax.
There is a very good posting about this on the BlackBerry Java development forum, complete with sample HTTP connection code.
Try using following It worked for me
http://maps.google.com/maps/geo?json&ll=9.6,73.7&;deviceside=false;ConnectionType=mds-public
If you are targeting OS5 and above you can use ConnectionFactory. This takes a lot of the hard work out of establishing the correct connection type.
精彩评论