| OLD | NEW |
| (Empty) |
| 1 #!mojo mojo:js_content_handler | |
| 2 // Demonstate a Mojo wrapper for the Geocoder JSON API. The application | |
| 3 // connects to geocoder_service.js which implements geocoder.mojom. | |
| 4 // To run this application with mojo_shell, set DIR to be the absolute path | |
| 5 // for this directory, then: | |
| 6 // mojo_shell file://$DIR/demo.js | |
| 7 | |
| 8 define("main", [ | |
| 9 "console", | |
| 10 "examples/js/maps/geocoder.mojom", | |
| 11 "mojo/public/js/core", | |
| 12 "mojo/public/js/unicode", | |
| 13 "mojo/services/public/js/application", | |
| 14 "third_party/js/url", | |
| 15 ], function(console, geocoder, core, unicode, application, url) { | |
| 16 | |
| 17 const Application = application.Application; | |
| 18 const Geocoder = geocoder.Geocoder; | |
| 19 const Result = geocoder.Result; | |
| 20 const Location = geocoder.Location; | |
| 21 const Status = geocoder.Status; | |
| 22 const Options = geocoder.Options; | |
| 23 const URL = url.URL; | |
| 24 | |
| 25 var geocoderService; | |
| 26 | |
| 27 function demoAddressToLocation() { | |
| 28 console.log("Demo GeocoderServce.AddressToLocation()"); | |
| 29 var addr = "1365 Shorebird way, Mountain View, CA"; | |
| 30 geocoderService.addressToLocation(addr, new Options).then( | |
| 31 function(rv) { | |
| 32 if (rv.status == Status.OK) { | |
| 33 for (var i = 0; i < rv.results.length; i++) { | |
| 34 var address = rv.results[i].formatted_address; | |
| 35 var location = rv.results[i].geometry.location; | |
| 36 console.log("Latitude,longitude for \"" + address + "\":"); | |
| 37 console.log(location.latitude + ", " + location.longitude); | |
| 38 | |
| 39 console.log(""); | |
| 40 demoLocationToAddress(); | |
| 41 } | |
| 42 } else { | |
| 43 console.log("Geocoder request failed status=" + rv.status); | |
| 44 } | |
| 45 }); | |
| 46 } | |
| 47 | |
| 48 function demoLocationToAddress() { | |
| 49 console.log("Demo GeocoderServce.LocationToAddress()"); | |
| 50 var coords = new Location({ | |
| 51 latitude: 37.41811752319336, | |
| 52 longitude: -122.07335662841797, | |
| 53 }); | |
| 54 geocoderService.locationToAddress(coords, new Options).then( | |
| 55 function(rv) { | |
| 56 if (rv.status == Status.OK) { | |
| 57 for (var i = 0; i < rv.results.length; i++) { | |
| 58 var address = rv.results[i].formatted_address; | |
| 59 var location = rv.results[i].geometry.location; | |
| 60 console.log("Latitude,longitude for \"" + address + "\":"); | |
| 61 console.log(location.latitude + ", " + location.longitude); | |
| 62 } | |
| 63 } else { | |
| 64 console.log("Geocoder request failed status=" + rv.status); | |
| 65 } | |
| 66 }); | |
| 67 } | |
| 68 | |
| 69 class Demo extends Application { | |
| 70 initialize() { | |
| 71 var geocoderURL = new URL(this.url).resolve("geocoder_service.js"); | |
| 72 geocoderService = this.shell.connectToService(geocoderURL, Geocoder); | |
| 73 demoAddressToLocation(); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 return Demo; | |
| 78 }); | |
| 79 | |
| OLD | NEW |