This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from pawerda/master
PlaceAutocomplete
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
var querystring = require("querystring"); | ||
var https = require("https"); | ||
|
||
var HttpResponseProcessor = require("./HttpResponseProcessor.js"); | ||
var validate = require("./validate.js"); | ||
|
||
module.exports = function (apiKey, outputFormat) { | ||
return function (parameters, callback) { | ||
validate.apiKey(apiKey); | ||
validate.outputFormat(outputFormat); | ||
//Required parameters | ||
parameters.key = apiKey; | ||
parameters.input = parameters.input || 'sydney lyr'; | ||
|
||
if (typeof parameters.location === "object") parameters.location = parameters.location.toString(); | ||
|
||
var options = { | ||
hostname: "maps.googleapis.com", | ||
path: "/maps/api/place/autocomplete/" + outputFormat + "?" + querystring.stringify(parameters) | ||
}; | ||
var request = https.request(options, new HttpResponseProcessor(outputFormat === "json", callback)); | ||
request.on("error", function (error) { | ||
callback(new Error(error)); | ||
}); | ||
request.end(); | ||
}; | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
var assert = require("assert"); | ||
|
||
var PlaceAutocomplete = require("../lib/PlaceAutocomplete.js"); | ||
var config = require("./config.js"); | ||
|
||
var placeAutocomplete = new PlaceAutocomplete(config.apiKey, config.outputFormat); | ||
|
||
var parameters = { | ||
input: 'sydney lyr' | ||
}; | ||
placeAutocomplete(parameters, function (error, response) { | ||
if (error) throw error; | ||
assert.equal(response.status, "OK", "Place autocomplete request response status is OK"); | ||
}); | ||
|
||
})(); |