|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
C#跟java类似,但是在跨平台方面理论上可以跨平台,实际上应用不大,执行性能优于java,跟C++基本一致,但是启动速度还是慢.代码安全,但容易性能陷阱.servicesJ2MEandLocation-BasedServices
Print-friendlyVersion
Location-basedservices(LBS)provideusersofmobiledevicespersonalizedservicestailoredtotheircurrentlocation.Theyopenanewmarketfordevelopers,cellularnetworkoperators,andserviceproviderstodevelopanddeployvalue-addedservices:advisingusersofcurrenttrafficconditions,supplyingroutinginformation,helpingthemfindnearbyrestaurants,andmanymore.
ThisarticleintroducesyoutothefieldofLBSandtotheLocationAPIforJ2ME(JSR179),asetofgenericAPIsthatcanbeusedfordevelopinglocation-basedservices.Inaddition,thearticleoffersguidelinesfordesigninglocation-basedservices.
WhatLocation-BasedServicesDo
Location-basedservicesanswerthreequestions:WhereamI?Whatsaroundme?HowdoIgetthere?Theydeterminethelocationoftheuserbyusingoneofseveraltechnologiesfordeterminingposition,thenusethelocationandotherinformationtoprovidepersonalizedapplicationsandservices.Asanexample,considerawireless911emergencyservicethatdeterminesthecallerslocationautomatically.Suchaservicewouldbeextremelyuseful,especiallytouserswhoarefarfromhomeanddontknowlocallandmarks.Trafficadvisories,navigationhelpincludingmapsanddirections,androadsideassistancearenaturallocation-basedservices.Otherservicescancombinepresentlocationwithinformationaboutpersonalpreferencestohelpusersfindfood,lodging,andentertainmenttofittheirtastesandpocketbooks.
Therearetwobasicapproachestoimplementinglocation-basedservices:
Processlocationdatainaserveranddeliverresultstothedevice.
Obtainlocationdataforadevice-basedapplicationthatusesitdirectly.
Thisarticlefocusesondevice-basedlocationservices.
DeterminingtheDevicesLocation
Todiscoverthelocationofthedevice,LBSmustusereal-timepositioningmethods.Accuracydependsonthemethodused.
Locationscanbeexpressedinspatialtermsorastextdescriptions.Aspatiallocationcanbeexpressedinthewidelyusedlatitude-longitude-altitudecoordinatesystem.Latitudeisexpressedas0-90degreesnorthorsouthoftheequator,andlongitudeas0-180degreeseastorwestoftheprimemeridian,whichpassesthroughGreenwich,England.Altitudeisexpressedinmetersabovesealevel.Atextdescriptionisusuallyexpressedasastreetaddress,includingcity,postalcode,andsoon.
Applicationscancallonanyofseveraltypesofpositioningmethods.
Usingthemobilephonenetwork:ThecurrentcellIDcanbeusedtoidentifytheBaseTransceiverStation(BTS)thatthedeviceiscommunicatingwithandthelocationofthatBTS.Clearly,theaccuracyofthismethoddependsonthesizeofthecell,andcanbequiteinaccurate.AGSMcellmaybeanywherefrom2to20kilometersindiameter.OthertechniquesusedalongwithcellIDcanachieveaccuracywithin150meters.
Usingsatellites:TheGlobalPositioningSystem(GPS),controlledbytheUSDepartmentofDefense,usesaconstellationof24satellitesorbitingtheearth.GPSdeterminesthedevicespositionbycalculatingdifferencesinthetimessignalsfromdifferentsatellitestaketoreachthereceiver.GPSsignalsareencoded,sothemobiledevicemustbeequippedwithaGPSreceiver.GPSispotentiallythemostaccuratemethod(between4and40metersiftheGPSreceiverhasaclearviewofthesky),butithassomedrawbacks:Theextrahardwarecanbecostly,consumesbatterywhileinuse,andrequiressomewarm-upafteracoldstarttogetaninitialfixonvisiblesatellites.Italsosuffersfrom"canyoneffects"incities,wheresatellitevisibilityisintermittent.
Usingshort-rangepositioningbeacons:Inrelativelysmallareas,suchasasinglebuilding,alocalareanetworkcanprovidelocationsalongwithotherservices.Forexample,appropriatelyequippeddevicescanuseBluetoothforshort-rangepositioning.
Inaddition,locationmethodscanconnecttoamobilepositioncenterthatprovidesaninterfacetoqueryforthepositionofthemobilesubscriber.TheAPItothemobilepositioncenterisXML-based.Whileapplicationscanbefullyself-containedonthedevice,itsclearthatawiderarrayofservicesispossiblewhenaserver-sideapplicationispartoftheoverallservice.
Someapplicationsdontneedhighaccuracy,butotherswillbeuselessifthelocationisntaccurateenough.Itsokayforthelocationofatouristwalkingaroundtowntobeoffby30meters,butotherapplicationsandservicesmaydemandhigheraccuracy.
TheLocationAPIforJ2ME
TheLocationAPIforJ2MEspecificationdefinesanoptionalpackage,javax.microedition.location,thatenablesdeveloperstowritewirelesslocation-basedapplicationsandservicesforresource-limiteddeviceslikemobilephones,andcanbeimplementedwithanycommonlocationmethod.ThecompactandgenericJ2MElocationAPIsprovidemobileapplicationswithinformationaboutthedevicespresentphysicallocationandorientation(compassdirection),andsupportthecreationanduseofdatabasesofknownlandmarks,storedinthedevice.
JSR179requirestheConnectedDeviceConfiguration(CDC)orversion1.1oftheConnectedLimitedDeviceConfiguration(CLDC).CLDC1.0isntadequatebecauseitdoesntsupportfloating-pointnumbers,whichtheAPIusestorepresentcoordinatesandothermeasurements.TheLocationAPIdoesntdependonanyparticularprofile--itcanbeusedwithMIDPorthePersonalProfile.
Thehardwareplatformdetermineswhichlocationmethodsaresupported.Ifitdoesntsupportatleastonelocationprovider,LBSwontbepossible.Applicationscanrequestproviderswithparticularcharacteristics,suchasaminimumdegreeofaccuracy.Somelocationmethodsmaybefree;othersmayentailservicefees.Theapplicationshouldwarntheuserbeforeanychargesareincurred.
Itisuptotheapplicationtodeterminethecriteriaforselectingthelocationmethod.Criteriafieldsinclude:accuracy,responsetime,needforaltitude,andspeed.OncetheapplicationobtainsaLocationProviderinstancethatmeetsthecriteria,itcanusethatobjecttoobtainthelocation,ineitheroftwoways:
Invokeamethodsynchronouslytogetasinglelocation.
Registeralistenerandgetperiodicupdatesatapplication-definedintervals.
TheLocationclassabstractsthelocationresults.Itsobjectcontainscoordinates,speedifavailable,textualaddressifavailable,andatimestampthatindicateswhenthelocationmeasurementsweremade.
Coordinatesarerepresentedbyeitheroftwoclasses:
ACoordinatesobjectrepresentsapointslatitudeandlongitudeindegrees,andaltitudeinmeters.
AQualifiedCoordinatesobjectcontainslatitude,longitude,andaltitude,andalsoanindicationoftheiraccuracy,representedastheradiusofanarea.
Thefollowingsegmentofcodedemonstrateshowtoobtainthepresentlocationofthedevicesynchronously:
...
//Setcriteriaforselectingalocationprovider:
//accurateto500metershorizontally
Criteriacr=newCriteria();
cr.setHorizontalAccuracy(500);
//Getaninstanceoftheprovider
LocationProviderlp=LocationProvider.getInstance(cr);
//Requestthelocation,settingaone-minutetimeout
Locationl=lp.getLocation(60);
Coordinatesc=l.getQualifiedCoordinates();
if(c!=null){
//Usecoordinateinformation
doublelat=c.getLatitude();
doublelon=c.getLongitude();
}
...
Landmarks
Alandmarkisalocationassociatedwithanameandadescription.Landmarkscanbestoredinadevice-baseddatabase,wheretheycanbesharedamongallJ2MEapplications.Landmarkscanstorefrequentlyusedlocations:home,office,favoriterestaurants,andsoon.EachisrepresentedbyaLandmarkinstance,andthedatabasebyaLandmarkStore.YoucancreatemultiplenamedLandmarkStorestogrouplocationsintocategoriessuchascinemas,museums,orcustomersites.
Ifthedeviceincludesacompass,theapplicationmaybeabletodeterminenotonlyitslocationbutitsorientation,whichisusefulinnavigationalapplications.TheOrientationclassrepresentsthedevicesazimuthasananglefromduenorth,whichtheapplicationcaneasilyconverttoacompassdirection.
SecurityandPrivacy
Manyusersconsiderlocationinformationtobehighlysensitive,andareconcernedaboutanumberofprivacyissues,including:
Targetmarketing:Mobileuserslocationscanbeusedtoclassifycustomersforfocusedmarketingefforts.
Embarrassment:Onecustomersknowledgeofanotherslocationmayleadtoembarrassingsituations.
Harassment:Locationinformationcanbeusedtoharassorattackauser.
Servicedenial:Ahealthinsurancefirmmightdenyaclaimifitlearnedthatauservisitedahigh-riskarea.
Legalrestrictions:Somecountriesregulatetheuseofpersonaldata.
Fortheseandotherreasons,usersmustknowwhentheirlocationisgiventoanapplication.
Guidelines
Keepthefollowingguidelinesinmindwhendesigninglocation-basedservices:
Handleunavailabilityofservicesgracefully.Theuserslocationmaynotalwaysbeavailable,foranyofseveralreasons.
Thedeviceiscutofffromanyofthelocationmethodsitsupports,inatunneloronanairplaneforexample.
Theuserwithholdspermissiontoreleasetheinformation.
Nolocationproviderthatthedevicesupportsisavailable.
Dependingonthemethodused,determiningthelocationmaytakealongtime.Thedelaymaybesolongthattheendresultisntusefulin,forexample,anavigationapplication.Keeptheuserinformed.
Locationservicefees,typicalofnetwork-assistedlocationmethods,canaddupquickly,sodontoverusefee-basedservices.
Besensitivetoprivacyconcerns.
Tellcustomersabouttheinformationbeingcollectedonthemandhowitwillbeused.
Offercustomersthechoiceofwhatlocationinformationtodisclose,andwhenappropriateanoptionnottoparticipate.
Allowcustomerstoreviewtheirpermissionprofilessothattheyknowwhattheyarepermitting.
Protectlocationinformationsothatitcannotbeaccessedbyunauthorizedpersons.
YoushouldalsotakefulladvantageoftheMIDP2.0securityframework,whichrestrictstheapplicationsaccesstolocationdatatocasesinwhichtheuserexplicitlyconfirmspermission.
Summary
ThroughtheLocationAPIforJ2ME,youcanuseinformationabouttheuserspositiontobuildnewkindsofapplicationsandservicesformobiledevicessuchascellphonesandPDAs,andtoenhanceexistingservices.JSR179specifiesagenericAPIforobtaininglocations,andthusmakesportingLBSapplicationstoawiderangeofdevicesmucheasier.ThecriticalissuethatLBSdevelopersmustaddressistheprivacyofthecustomer.Toensureprivacy,followsoundprogrammingguidelinesandusethesecurityframeworkinMIDP2.0.
到时我们不用学struts,不用学spring,不用学Hibernate,只要能把jsf学会了,完全可以替代所有的框架,包括AJAX,都知道AJAX并不是新技术,虽说我没深入学习jsf但我认为jsf应该已经能通过其它技术替代AJAX,实现无缝刷新。 |
|