Giter Site home page Giter Site logo

Comments (2)

skynet2 avatar skynet2 commented on May 17, 2024

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

from ngx-google-places-autocomplete.

almino avatar almino commented on May 17, 2024

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
                    }
                }
            );
        }
    }
}

from ngx-google-places-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.