Resolve and code addresses using geocoding
文章推薦指數: 80 %
Documentation for HERE's HERE Maps API for Javascript. ... The HERE Geocoding and Search API unlocks the search and geocoding capabilities of HERE services ... DeveloperHEREMapsAPIforJavaScriptGuideAPIReferenceReleaseNotesExamplesResolveandcodeaddressesusinggeocoding·MapsAPIforJavaScriptVisitwww.here.comIntroductionGetstarted-HEREplatformGetstarted-HEREdeveloperportalBrowsersupportModulesAPIVersionsMigrationtotheMapsAPIforJavaScript3.1ConceptsMaptypesVectormaptypesStructureoverviewDefaultstylesCustomstylesFiltersSourcesGeopoliticalviewsRastermaptypesMapeventsMapobjectsMarkerobjectsOverlaysGeoshapesTutorialsGetstartedwithJapandataBundleHEREMapsAPIforJavaScriptModifyyourmapusingmapcontrolsandUIResolveandcodeaddressesusinggeocodingCalculateroutesRetrieveanddisplaytrafficdataClustermapdatasetsShowFleetTelematicsAdvancedDataSetslayeronthemapShowFleetTelematicsCustomLocationslayeronthemapCreatecontentusingKMLsupportDisplayaDataHubspaceonthemapIntegrateIndoorMapsWorkingwithReactWorkingwithAngularWorkingwithTypeScriptSettingdomainnameandservicepathBestpracticesResolveandcodeaddressesusinggeocodingResolveandcodeaddressesusinggeocodingResolvingaddressestogeocoordinatesandviceversaarecommonrequirementsforlocation-basedapplications.TheHEREGeocodingandSearchAPIunlocksthesearchandgeocodingcapabilitiesofHEREservicestoprovidedeveloperswithunmatchedflexibilitytocreatedifferentiatinglocation-enabledapplications.Italsosupportsareversegeocoding(obtainingastreetaddressthatcorrespondstoasetofgeo-coordinates)aswellaslandmarkgeocoding(findingairportsorlandmarksclassifiedasnationallyimportant).AllthesefeaturescanbeaccessedthroughtheMapAPI'sservicemodule(mapsjs-service.js)foreasyintegrationintoamapapplication.DisplayinggeocodingresultsonamapThefollowingexampleshowshowtogeocodetheaddress200SMathildaAve,Sunnyvale,CAandplaceamarkeratthereturnedlocationonthemap.Thecodesubmitsageocodingrequest,providingcallbackfunctionstohandletheresults.TherequestusesanobjectliteralwithmembersmatchingtheparameternamessupportedbytheHEREHEREGeocodingandSearchAPI.ThecontentsofspecifiedobjectliteralareconvertedbytheMapsAPItoURLparameters.TheparameterobjectcanincludeanyparametersrecognizedbytheHEREGeocodingandSearchAPI.Therequestisprocessedasynchronously,whichiswhythecallbacksareneeded.Thecallbackfunctioninvokedonsuccessplacesthemarkeronthemap,whiletheerrorcallbacksimplydisplaysanalert.//Instantiateamapandplatformobject: varplatform=newH.service.Platform({ 'apikey':'{YOUR_API_KEY}' }); //Getaninstanceofthegeocodingservice: varservice=platform.getSearchService(); //Callthegeocodemethodwiththegeocodingparameters, //thecallbackandanerrorcallbackfunction(calledifa //communicationerroroccurs): service.geocode({ q:'200SMathildaAve,Sunnyvale,CA' },(result)=>{ //Addamarkerforeachlocationfound result.items.forEach((item)=>{ map.addObject(newH.map.Marker(item.position)); }); },alert); Asuccessfulgeocodingrequestallowsthecodetodisplayamarkerforeachlocationfoundasshownintheimagebelow:Figure1.Themapafterretrievingthegeo-coordinatesfortheaddressReversegeocodingmaplocationsThefollowingexampleshowshowtoretrievetheaddressofthespecifiedpositioninBerlin,Germany(52.5309°N13.3847°E).Theresultisdisplayedonthemapwithaninfobubblemarkingthelocationoftheretrievedaddress.//Instantiateamapandplatformobject: varplatform=newH.service.Platform({ 'apikey':'{YOUR_API_KEY}' }); //Getaninstanceofthesearchservice: varservice=platform.getSearchService(); //Callthereversegeocodemethodwiththegeocodingparameters, //thecallbackandanerrorcallbackfunction(calledifa //communicationerroroccurs): service.reverseGeocode({ at:'52.5309,13.3847,150' },(result)=>{ result.items.forEach((item)=>{ //Assumption:uiisinstantiated //CreateanInfoBubbleatthereturnedlocationwith //theaddressasitscontents: ui.addBubble(newH.ui.InfoBubble(item.position,{ content:item.address.label })); }); },alert); Figure2.ThemapshowingtheretrievedaddressofalocationAutosuggestTheautosuggestendpointimprovesuser'ssearchexperiencebyallowingsubmittaloffree-form,incompleteandmisspelledaddressesorplacenamestotheendpoint.ThefollowingexampleshowshowtosearchforChicagoO'HareInternationalAirport(ORD).//Instantiateamapandplatformobject: varplatform=newH.service.Platform({ 'apikey':'{YOUR_API_KEY}' }); //Getaninstanceofthesearchservice: varservice=platform.getSearchService(); //Callthe"autosuggest"methodwiththesearchparameters, //thecallbackandanerrorcallbackfunction(calledifa //communicationerroroccurs): service.autosuggest({ //Searchquery q:'ChicagoORD', //Centerofthesearchcontext at:'38.71014896078624,-98.60787954719035' },(result)=>{ let{position,title}=result.items[0]; //Assumption:uiisinstantiated //CreateanInfoBubbleatthereturnedlocation ui.addBubble(newH.ui.InfoBubble(position,{ content:title })); },alert); Whentherequestissuccessful,thecallbackfunctiondisplaysaninfobubbleonthemap:Figure3.Themapafterretrievinglandmarkinformationresultsmatching""Noresultsmatching""
延伸文章資訊
- 1Overview | Geocoding API - Google Developers
Geocoding converts addresses into geographic coordinates to be placed on a map. Reverse Geocoding...
- 2Google Maps V3 - Geocoder example - gists · GitHub
Google Maps V3 - Geocoder example. GitHub Gist: instantly share code, notes, and snippets.
- 3Google Maps Geocoding a string - Stack Overflow
I want to be able to geocode a string within my code and place a marker at the location, rather t...
- 4Geocoding Service | Maps JavaScript API - Google Developers
This example creates a map along with a text input field and a button. When you click the "geocod...
- 5Resolve and code addresses using geocoding
Documentation for HERE's HERE Maps API for Javascript. ... The HERE Geocoding and Search API unlo...