Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <ion-row>
  2. <ion-item>
  3. <ion-label>Search</ion-label>
  4. <ion-input id="places" type="text" name="search"></ion-input>
  5. </ion-row>
  6. <div #map id="map"></div>
  7.  
  8. export class HomePage {
  9.  
  10. public latitude: number;
  11. public longitude: number;
  12.  
  13. @ViewChild('map') mapElement;
  14. map: any;
  15. marker: any;
  16. search: string;
  17.  
  18. constructor(public navCtrl: NavController, public platform: Platform) {
  19. /*platform.ready().then(() => {
  20. this.InitMap();
  21. });*/
  22. }
  23. ionViewDidLoad(){
  24. this.InitMap();
  25. }
  26.  
  27. InitMap() {
  28.  
  29. this.setLocation();
  30. let input = document.getElementById('places');
  31. let autocomplete = new google.maps.places.Autocomplete(input);
  32.  
  33. google.maps.event.addListener(autocomplete, 'place_changed', () => {
  34.  
  35. let place = autocomplete.getPlace();
  36. this.latitude = place.geometry.location.lat();
  37. this.longitude = place.geometry.location.lng();
  38. alert(this.latitude + ", " + this.longitude);
  39. console.log(place);
  40. });
  41.  
  42. }
  43.  
  44. setLocation() {
  45.  
  46. let latLng = new google.maps.LatLng(53.550513, 9.994241);
  47. let mapOptions = {
  48. center: latLng,
  49. zoom: 15,
  50. mapTypeId: google.maps.MapTypeId.ROADMAP
  51. };
  52.  
  53. this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
  54. this.marker = new google.maps.Marker({
  55. position: latLng,
  56. map: this.map,
  57. });
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement