-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kien Tran
committed
Oct 6, 2018
1 parent
8886e0e
commit 3155271
Showing
10 changed files
with
108,537 additions
and
103 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 |
---|---|---|
@@ -1,41 +1,75 @@ | ||
import { Observable } from 'rxjs'; | ||
import { Location, LocationRepository } from 'weather-domain'; | ||
import {RxHR} from "@akanass/rx-http-request"; | ||
import {createClient} from 'react-native-google-maps-services'; | ||
import * as RxJs from 'rxjs'; | ||
import * as RxJsOperators from 'rxjs/operators' | ||
|
||
import { Location, LocationRepository } from 'weather-domain'; | ||
import Axios, * as axios from "axios"; | ||
import { createClient } from 'react-native-google-maps-services'; | ||
// import { map, flatMap } from 'rxjs/operators'; | ||
// import {} from '@reactivex/rxjs' | ||
// import 'rxjs/Rx' | ||
export class DefaultLocationRepository implements LocationRepository { | ||
searchCity(searchText: string): Observable<Location> { | ||
return Observable.create(function (observer) { | ||
searchCity(searchText: string): RxJs.Observable<Location> { | ||
return RxJs.Observable.create(function (observer) { | ||
const key = "AIzaSyBO35s72ZQbDBabY1y9JsW59SBsHKcIfC8" | ||
const uri = "https://maps.googleapis.com/maps/api/place/autocomplete/json?key="+ key +"&input=" + searchText + "&types=(cities)" | ||
|
||
const client = createClient({ | ||
key: "AIzaSyDyp4K2oq2GDsHRIzy7Qpt87gGmlCRnvuI" | ||
|
||
// axios.default.defaults.headers["referer"] = "http://kienhiepsi.com" | ||
axios.default.get(uri) | ||
.then( response => { | ||
if (response.status == 200) { | ||
var results: Array<Location> = [] | ||
console.log(response.data) | ||
for (const prediction of response.data["predictions"]) { | ||
var structured_formatting = prediction.structured_formatting | ||
var mainText = structured_formatting.main_text | ||
var secondaryText = structured_formatting.secondary_text | ||
|
||
results.push(new Location( | ||
mainText, secondaryText | ||
)) | ||
} | ||
|
||
observer.next(results) | ||
} | ||
// console.log(response); // Show the JSON response object. | ||
}) | ||
let query = { | ||
input: searchText | ||
} | ||
|
||
client.placesAutoComplete(query, | ||
function (err, response) { | ||
if (response) { | ||
|
||
var results:Array<Location> = [] | ||
for (const prediction of response.json.predictions) { | ||
var structured_formatting = prediction.structured_formatting | ||
var mainText = structured_formatting.main_text | ||
var secondaryText = structured_formatting.secondary_text | ||
|
||
results.push(new Location( | ||
mainText, secondaryText | ||
)) | ||
} | ||
|
||
observer.next(results) | ||
} else { | ||
console.log(err) | ||
|
||
observer.error(err) | ||
} | ||
}) | ||
.catch( error => { | ||
console.log(error); // Show the JSON response object. | ||
|
||
observer.error(error) | ||
}) | ||
|
||
// RxHR.get(uri, options).subscribe( | ||
// data => { | ||
// if (data.response.statusCode === 200) { | ||
// var results: Array<Location> = [] | ||
// for (const prediction of data.body.predictions) { | ||
// var structured_formatting = prediction.structured_formatting | ||
// var mainText = structured_formatting.main_text | ||
// var secondaryText = structured_formatting.secondary_text | ||
|
||
// results.push(new Location( | ||
// mainText, secondaryText | ||
// )) | ||
// } | ||
|
||
// observer.next(results) | ||
// } | ||
// }, | ||
// error => { | ||
|
||
// } | ||
// ) | ||
// }) | ||
}) | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
// var repository = new DefaultLocationRepository() | ||
// repository.searchCity('ho').subscribe( | ||
// locations => console.log(locations), | ||
// error => console.log(error) | ||
// ) |
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
Oops, something went wrong.