小妖女 发表于 2015-1-18 11:35:43

JAVA网页编程之J2ME and Location-Based Services

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,实现无缝刷新。

深爱那片海 发表于 2015-1-21 10:41:19

接着就是EJB了,EJB就是Enterprise JavaBean, 看名字好象它是Javabean,可是它和Javabean还是有区别的。它是一个体系结构,你可以搭建更安全、更稳定的企业应用。它的大量代码已由中间件(也就是我们常听到的 Weblogic,Websphere这些J2EE服务器)完成了,所以我们要做的程序代码量很少,大部分工作都在设计和配置中间件上。

飘灵儿 发表于 2015-1-28 05:40:07

一直感觉JAVA很大,很杂,找不到学习方向,前两天在网上找到了这篇文章,感觉不错,给没有方向的我指了一个方向,先不管对不对,做下来再说。

愤怒的大鸟 发表于 2015-2-4 14:51:44

还好,SUN提供了Javabean可以把你的JSP中的 Java代码封装起来,便于调用也便于重用。

不帅 发表于 2015-2-10 01:48:38

http://www.jdon.com/去下载,或到同济技术论坛的服务器ftp://nro.shtdu.edu.cn去下,安装上有什么问题,可以到论坛上去提问。

第二个灵魂 发表于 2015-2-26 14:44:34

多重继承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的对象所占据的内存空间,使得程序员不用再为内存管理而担忧。在 Java 1.5 版本中,Java 又引入了泛型编程(Generic Programming)、类型安全的枚举、不定长参数和自动装/拆箱等语言特性。

若天明 发表于 2015-2-27 13:12:29

http://www.jdon.com/去下载,或到同济技术论坛的服务器ftp://nro.shtdu.edu.cn去下,安装上有什么问题,可以到论坛上去提问。

因胸联盟 发表于 2015-3-9 05:46:13

自从Sun推出Java以来,就力图使之无所不包,所以Java发展到现在,按应用来分主要分为三大块:J2SE,J2ME和J2EE,这也就是Sun ONE(Open Net Environment)体系。J2SE就是Java2的标准版,主要用于桌面应用软件的编程;J2ME主要应用于嵌入是系统开发,如手机和PDA的编程;J2EE是Java2的企业版,主要用于分布式的网络程序的开发,如电子商务网站和ERP系统。

简单生活 发表于 2015-3-15 05:07:32

http://www.jdon.com/去下载,或到同济技术论坛的服务器ftp://nro.shtdu.edu.cn去下,安装上有什么问题,可以到论坛上去提问。

冷月葬花魂 发表于 2015-3-17 20:54:41

另外编写和运行Java程序需要JDK(包括JRE),在sun的官方网站上有下载,thinking in java第三版用的JDK版本是1.4,现在流行的版本1.5(sun称作J2SE 5.0,汗),不过听说Bruce的TIJ第四版国外已经出来了,是专门为J2SE 5.0而写的。

灵魂腐蚀 发表于 2015-3-20 14:20:33

是一种由美国SUN计算机公司(Sun Microsystems, Inc.)所研究而成的语言

山那边是海 发表于 2015-4-3 03:08:10

还好,SUN提供了Javabean可以把你的JSP中的 Java代码封装起来,便于调用也便于重用。

飘飘悠悠 发表于 2015-4-13 20:16:34

当然你也可以参加一些开源项目,一方面可以提高自己,另一方面也是为中国软件事业做贡献嘛!开发者在互联网上用CVS合作开发,用QQ,MSN,E-mail讨论联系,天南海北的程序员分散在各地却同时开发同一个软件,是不是很有意思呢?

蒙在股里 发表于 2015-4-14 13:08:26

是一种由美国SUN计算机公司(Sun Microsystems, Inc.)所研究而成的语言

海妖 发表于 2015-4-16 08:09:21

如果要向java web方向发展也要吧看看《Java web从入门到精通》学完再到《Struts2.0入门到精通》这样你差不多就把代码给学完了。有兴趣可以看一些设计模块和框架的包等等。

柔情似水 发表于 2015-5-1 14:02:23

你可以去承接一些项目做了,一开始可能有些困难,可是你有技术积累,又考虑周全,接下项目来可以迅速作完,相信大家以后都会来找你的,所以Money就哗啦啦的。。。。。。

小妖女 发表于 2015-5-4 11:46:47

有时间再研究一下MVC结构(把Model-View-Control分离开的设计思想)

活着的死人 发表于 2015-5-6 16:12:00

关于设计模式的资料,还是向大家推荐banq的网站 http://www.jdon.com/,他把GOF的23种模式以通俗易懂的方式诠释出来,纯Java描述,真是经典中的经典。

再见西城 发表于 2015-5-11 02:51:47

象、泛型编程的特性,广泛应用于企业级Web应用开发和移动应用开发。
页: [1]
查看完整版本: JAVA网页编程之J2ME and Location-Based Services