-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maps): add google map with access search location dropdown
- Loading branch information
1 parent
cb5795b
commit 97c7134
Showing
13 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,4 @@ | ||
export class Location { | ||
constructor(public latitude: number = 54, public longitude: number = 33) { | ||
} | ||
} |
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,7 @@ | ||
<agm-map [latitude]="latitude" | ||
[longitude]="longitude" | ||
[scrollwheel]="false" | ||
[zoom]="zoom"> | ||
<agm-marker [latitude]="latitude" | ||
[longitude]="longitude"></agm-marker> | ||
</agm-map> |
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,13 @@ | ||
@import '../../../../@theme/styles/themes'; | ||
|
||
@include nb-install-component() { | ||
|
||
nb-card-body { | ||
padding: 0; | ||
} | ||
|
||
/deep/ agm-map { | ||
width: 100%; | ||
height: nb-theme(card-height-large); | ||
} | ||
} |
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,31 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { Location } from '../entity/Location'; | ||
|
||
@Component({ | ||
selector: 'ngx-map', | ||
templateUrl: './map.component.html', | ||
styleUrls: ['./map.component.scss'], | ||
}) | ||
export class MapComponent implements OnInit { | ||
latitude: number; | ||
longitude: number; | ||
zoom: number; | ||
|
||
@Input() | ||
public set searchedLocation(searchedLocation: Location) { | ||
this.latitude = searchedLocation.latitude; | ||
this.longitude = searchedLocation.longitude; | ||
this.zoom = 12; | ||
} | ||
|
||
ngOnInit(): void { | ||
// set up current location | ||
if ('geolocation' in navigator) { | ||
navigator.geolocation.getCurrentPosition((position) => { | ||
this.searchedLocation = new Location( | ||
position.coords.latitude, position.coords.longitude, | ||
); | ||
}); | ||
} | ||
} | ||
} |
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,7 @@ | ||
<nb-card> | ||
<nb-card-header>Google Maps with search</nb-card-header> | ||
<nb-card-body> | ||
<ngx-search (positionChanged)="updateLocation($event)"></ngx-search> | ||
<ngx-map [searchedLocation]="searchedLocation"></ngx-map> | ||
</nb-card-body> | ||
</nb-card> |
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,15 @@ | ||
import { Component } from '@angular/core'; | ||
import { Location } from './entity/Location'; | ||
|
||
@Component({ | ||
selector: 'ngx-search-map', | ||
templateUrl: './search-map.component.html', | ||
}) | ||
export class SearchMapComponent { | ||
|
||
searchedLocation: Location = new Location(); | ||
|
||
updateLocation(event: Location) { | ||
this.searchedLocation = new Location(event.latitude, event.longitude); | ||
} | ||
} |
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,4 @@ | ||
<div class="form-group"> | ||
<input placeholder="search for location" autocorrect="off" autocapitalize="off" spellcheck="off" type="text" | ||
class="form-control search-location" #search> | ||
</div> |
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,44 @@ | ||
import { Component, ElementRef, EventEmitter, NgZone, OnInit, Output, ViewChild } from '@angular/core'; | ||
import { MapsAPILoader } from '@agm/core'; | ||
import { Location } from '../entity/Location'; | ||
import {} from 'googlemaps'; | ||
|
||
@Component({ | ||
selector: 'ngx-search', | ||
templateUrl: './search.component.html', | ||
}) | ||
export class SearchComponent implements OnInit { | ||
|
||
@Output() positionChanged = new EventEmitter<Location>(); | ||
|
||
@ViewChild('search') | ||
public searchElementRef: ElementRef; | ||
|
||
constructor(private mapsAPILoader: MapsAPILoader, | ||
private ngZone: NgZone) { | ||
} | ||
|
||
ngOnInit() { | ||
// load Places Autocomplete | ||
this.mapsAPILoader.load().then(() => { | ||
const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement, { | ||
types: ['address'], | ||
}); | ||
autocomplete.addListener('place_changed', () => { | ||
this.ngZone.run(() => { | ||
// get the place result | ||
const place: google.maps.places.PlaceResult = autocomplete.getPlace(); | ||
|
||
// verify result | ||
if (place.geometry === undefined || place.geometry === null) { | ||
return; | ||
} | ||
|
||
this.positionChanged.emit( | ||
new Location(place.geometry.location.lat(), | ||
place.geometry.location.lng())); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
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