Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use current location #2

Closed
balajivmdu opened this issue Jan 10, 2018 · 2 comments
Closed

How to use current location #2

balajivmdu opened this issue Jan 10, 2018 · 2 comments

Comments

@balajivmdu
Copy link

Am beginner to Angular. Its awesome tool to use and easy to use.

But my issue us , Its not showing "Current location" option in autocomplete.
Please help me in this.

@balajivmdu balajivmdu changed the title Use curent location How to use current location Jan 10, 2018
@skynet2
Copy link
Owner

skynet2 commented Jan 10, 2018

Hi @balajivmdu ,

I`m not sure but looks like google places autocomplete does not have functionality to receive current position https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete?hl=en

Probably you need to use geolocation service from https://developers.google.com/maps/documentation/javascript/geolocation

@skynet2 skynet2 closed this as completed Jan 11, 2018
@almino
Copy link

almino commented Mar 11, 2018

I've managed to get current location using HTML Geolocation API. But how to cast it to LatLngBounds?

Here's my code: options.model.ts

import { Options as PlacesOptions } from 'ngx-google-places-autocomplete/objects/options/options';
import { ComponentRestrictions } from 'ngx-google-places-autocomplete/objects/options/componentRestrictions';
import { LatLngLiteral } from 'ngx-google-places-autocomplete/objects/latLng';

export class Options extends PlacesOptions {

    public componentRestrictions : ComponentRestrictions = new ComponentRestrictions({
        country: 'BR'
    });
    
    // public bounds: LatLngBounds = [];

    constructor(opt?: Partial<PlacesOptions>) {
        super(opt);

        /* Gets users current geolocation */
        if (this.bounds === undefined && window.navigator.geolocation) {
            window.navigator.geolocation.watchPosition(
                (position) => {
                    let latlng : LatLngLiteral = {
                        lat: position.coords.latitude,
                        lng: position.coords.longitude
                    }

                    this.bounds = {
                        latLng: latlng
                    }
                }
            );
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants