Giter Site home page Giter Site logo

ng4-geoautocomplete's Introduction

Angular 4 compatible google autocomplete

Build Status codecov npm version devDependency Status GitHub issues GitHub stars GitHub license

Demo

https://tanoy009.github.io/ng4-geoautocomplete/

Test Case.

In Pipeline will be updated in a while.

Table of contents

About

angular 4 compatible google autocomplete with server side api support and AOT enabled

Installation

Install through npm:

npm install --save ng4-geoautocomplete

Then include in your apps module:

import { Component, NgModule } from '@angular/core';
import { Ng4GeoautocompleteModule } from 'ng4-geoautocomplete';

@NgModule({
  imports: [
    Ng4GeoautocompleteModule.forRoot()
  ]
})
export class MyModule {}

Add google place script in your main file generally referred to 'index.html' (Optional if you want to use google services).

<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=true&key=XXReplace this with valid keyXX&libraries=places&language=en-US"></script>

Finally use in one of your apps components:

import { Component } from '@angular/core';

@Component({
  template: '<ng4geo-autocomplete [userSettings]="userSettings" (componentCallback)="autoCompleteCallback1($event)"></ng4geo-autocomplete>'
})
export class MyComponent {
  userSettings = {}
	autoCompleteCallback1(selectedData:any) {
		//do any necessery stuff.
	}
  
}

List of settings that can be used to configure the module (all config. are optional):

	{
    geoPredictionServerUrl?: string;      //should be a server url which returns list of places upon input query (GET request)
    geoLatLangServiceUrl?: string;        //should be a server url which returns place object upon lat and lon. (GET request)
    geoLocDetailServerUrl?: string;       //should be a server url which returns place details upon placeID received by 'geoPredictionServerUrl' (GET request)
    geoCountryRestriction?: any;          //should be an array of country code where search should be restricted like ['in', 'us', 'pr', 'vi', 'gu', 'mp'] *(Default: 'no restriction')*
    geoTypes?: any;                       //should be an array of Place types defined by [Google api](https://developers.google.com/places/web-service/autocomplete#place_types).
    geoLocation?: any;                    //should be an array in the format [latitude,longitude]. This feature will not work if country restriction is implimented.
    geoRadius?: number;                   //should be a number and should only be used with 'geoLocation'.
    serverResponseListHierarchy?: any;    //should be an array of key from where 'geoPredictionServer' data should be extracted. (see Example.)
    serverResponseatLangHierarchy?: any;  //should be an array of key from where 'geoLatLangService' data should be extracted. (see Example.)
    serverResponseDetailHierarchy?: any;  //should be an array of key from where 'geoLocDetailSerice' data should be extracted. (see Example.)
    resOnSearchButtonClickOnly?: boolean; //when output should be emmited when search button clicked only.
    useGoogleGeoApi?: boolean;            //should set to 'false' when server urls to be used instade of google api. *(Default: true)*
    inputPlaceholderText?: string;        //Input Placeholder text can be changed *(Default: 'Enter Area Name')*
    inputString?: string;                 //Default selected input like prefefined address. *(Default: ''). See Example 3 in Demo after 10 sec*
    showSearchButton?: boolean;           //Search button to be visible or not. *(Default: true)*
    showRecentSearch?: boolean;           //Recent search to be saved & shown to user or not. *(Default: true)*
    showCurrentLocation?: boolean;        //current location option to be visible or not. *(Default: true)*
    recentStorageName?: string;           //Recent seraches are saved in browser localsorage. The key value which is used by the module to save can be changed. *(Default: 'recentSearches')*
    noOfRecentSearchSave?: number;        //Number of recent user entry to be saved . *(Default: 5)*
    currentLocIconUrl?: string;           //Current location icon can be changed *(Should be an image url or svg url)*
    searchIconUrl?: string;               //Search icon can be changed *(Should be an image url or svg url)*
    locationIconUrl?: string;             //General Location icon can be changed *(Should be an image or svg url)*
	}

NOTE: Component settings can also be altered after component initialization. Please follow the below method to change.

this.userSettings: any = {
  inputPlaceholderText: 'This is the placeholder text doring component initialization'
}

this.userSettings['inputPlaceholderText'] = 'This is the placeholder text after doing some external operation after some time';
this.userSettings = Object.assign({},this.userSettings) //Very Important Line to add after modifying settings.

NOTE:

'geoTypes' can be used for multiple Place Types like ['(regions)', '(cities)'] OR ['(regions)', 'establishment', 'geocode']. This will make individual api call for each Place Types to google to fetch lists and then it will merge the resuts with uniqueness.To know avalable Place Types please refer Google api.USE THIS FEATURE CAREFULLY

You may also find it useful to view the demo source.

You can change the component css in the below manner (You have to set encapsulation to None)

import { Component, ViewEncapsulation } from '@angular/core';

@Component({
  selector: 'any-component-name',
  encapsulation: ViewEncapsulation.None,
  template: '<div class="demo"><ng4geo-autocomplete (componentCallback)="autoCompleteCallback1($event)"></ng4geo-autocomplete></div>',
  styles: ['
  .demo #search_places {
    height: 100px;
  }
']
})

You can use it with system js as well

'ng4-geoautocomplete': 'npm:ng4-geoautocomplete/bundles/ng4-geoautocomplete.umd.js'

Usage without a module bundler

<script src="node_modules/ng4-geoautocomplete/bundles/ng4-geoautocomplete.umd.js"></script>
<script>
    // everything is exported ng4Geoautocomplete namespace
</script>

Documentation

All documentation is auto-generated from the source via compodoc and can be viewed here: https://tanoy009.github.io/ng4-geoautocomplete/docs/

Development

Prepare your environment

  • Install Node.js and NPM
  • Install local dev dependencies: npm install while current directory is this repo

Development server

Run npm start to start a development server on port 8000 with auto reload + tests.

Testing

Run npm test to run tests once or npm run test:watch to continually run tests.

Release

  • Bump the version in package.json (once the module hits 1.0 this will become automatic)
npm run release

License

MIT

ng4-geoautocomplete's People

Contributors

ishan123456789 avatar marabesi avatar smoke avatar tanoy009 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ng4-geoautocomplete's Issues

Angular 5 build issue - rxjs/Rx.js should be removed

@ ./node_modules/rxjs/_esm5/observable/bindNodeCallback.js 2:0-76
@ ./node_modules/rxjs/_esm5/add/observable/bindNodeCallback.js
@ ./node_modules/rxjs/_esm5/Rx.js
@ ./node_modules/ng4-geoautocomplete/auto-complete.service.js
@ ./src/app/app.module.ngfactory.js

Can you guys fix this issue please

Clear input event

How can I subscribe to event when user removes all content from input so I can clear lat/lng in my model?

Server API specs

The demo shows that the library is capable of using a server API instead of using Google. I was wondering if there is any information available over this API, how woud I implement it on my own server?

How to set country restriction

Ignore this - i found it from looking through your samples - Awesome work!

Hi there - this is looking good, but I can't see how i can set the country restriction - all searches are returning results from India - the documentation link seemed to be dead too.
Cheers

Issue Placeholder in Firefox

Hi,

In Firefox version 54.0.1 the color of the placeholder is not shown.

Probably a problem with the -moz properties.

Have a nice day,

Mickael Romaniello

How can I clear the selected location?

I have a scenario where the user will search and select a location using the autocomplete component. After some logic, I would like to reset/clear the selected location so that the user can search for a new location.

Modify inputPlaceholderText from a string(request)

Hi,

I want to replace the setting "inputPlaceholderText" by a string :

public nameInput: string;

Replace it like this:
inputPlaceholderText: this.nameInput

Instead of :
inputPlaceholderText: 'Enter a postal address',

The problem actually when I try.

The "inputPlaceholderText" return the default string 'Enter Area Name'.

My goal:

I have a request from my server, in this request I get the address of a user and I want to show the string address in the input of ng4geo-autocomplete.

Have a great day!

Mickael

How to implement closeAutocomplete method

Hi All,
I am using ng4-autocomplete component inside my custom component and I want to detect the change when the autocomplete dropdown closes. Can you please let me know how do you implement "closeAutocomplete" method?

Thanks!

Edit input

Hello. I need your assistance.
How can I add formControlName, ngModel, class or something like this into the input tag?

Thank you!

angular 8 upgrading issue

We are getting the below issue while updating the angular version from 7 to 8. We are not able to update the latest version because of the issue.

ng4-geoautocomplete has an incompatible peer dependency to "@angular/core" (requires ">=2.0.0 <5.0.0" (extended), would install "8.2.5

Ng4GeoautocompleteModule.forRoot()

Ng4GeoautocompleteModule use this module inside shared module, How can I export it?
It didn't work with ng build --prod flag
but it's work with ng serve

How to get actual current location

Hello,
I am not getting my actual current location by default it's taking the network or may be server provider current location which is far from 5-7 K.M from my actual location.
can you guide me how to fetch exact current location on autocomplete.

Error Handling

How to handle errors? For example, If user not allow to access current location or blocked, how can we handle this scenario?

How to remove the script from the index.html to use useGoogleGeoApi ?

I tried to removed the script of index.html

<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=myKey&libraries=places"></script>

to

  public userSettings5: any = {
    geoCountryRestriction: ['fr'],
    geoTypes: ['address'],
    showSearchButton: false,
    showRecentSearch: false,
    useGoogleGeoApi: true
  };

But not work

Edit components labels

I need to translate labels of application but today labels are hardcode, so I think it's a good idea to add some inputLabels settings, where I can inform the Labels when I want.

I have made some changes but I can't open a PR. Can you plz help?

Css

snap3
Hi,

This is a very nice component.

I was wondering, is there anyway I can use bootstrap style in the component. I need to use something similar style to form-control class of bootstrap.

Could you gimme any idea?

Thanks

Emit event when inputString attribute are cleared

Description:
When user inputString of UserSettings interface, component load with the configured string correctly, but no event was emitted when the user clears this string, the event only will be fired when address come from component search engine.

To check the issue you can use example 3 of geoautcomplete example list (https://tanoy009.github.io/ng4-geoautocomplete/)
clear the "Bangalore, karnataka" entries end you can check that no event is fired but with you search a new address and clear this address an output event with no input event was fired.
As you can see in my example of userSetting below I'm using the component without the search button.

Lib version: "ng4-geoautocomplete": "^0.1.0"
related issue: #43

Example:

            this.userSettings = {
                geoCountryRestriction: ['br'],
                geoLocation: [this.myLat, this.myLng],
                showSearchButton: false,
                inputPlaceholderText: 'Buscar Endereço',
                noOfRecentSearchSave: 5,
                inputString: 'Some address'
            };

Awesome, but how to style it though,

The module is woking fine but I am having troubles overriding the current styles, I am using material design and I want to change the 'box shap'
screen shot 2018-02-28 at 20 11 27

[Information]systemjs.config

Hi,

It will be good to add in the documentation that we need to modify systemjs.config.

Code:
'ng4-geoautocomplete': 'npm:ng4-geoautocomplete/bundles/ng4-geoautocomplete.umd.js'

Have a great day!

Thank you for the lib!

How to return just lat or lng?

Hello,

Please, how can I return just an element, not the full result.

myresult

html

<ng4geo-autocomplete [userSettings]="userSettings3" (componentCallback)="autoCompleteCallback1($event)"></ng4geo-autocomplete>
<samp style="word-wrap: break-word;">{{ componentData1 }}</samp>

ts

public componentData1: any = {};

public userSettings3: any = {
inputPlaceholderText: 'Saisissez votre adresse complète',
geoCountryRestriction: ['fr'],
};

autoCompleteCallback1(data: any): any {
this.componentData1 = JSON.stringify(data);
}

For exemple just return the lat or the lng.
I've tried many exemples: {{ result[0]location.lat }} / {{ geometry.location.lat }} /
{{ componentData1.geometry.location.lat }} ...

Thank You

Translate widget

Hi

Is it possible to translate or change string for "Use current location" and "recent searches ?

Thanks

Angular 5 error ng build --prod

Hello, I'm trying to build with --prod flag, but y got this problem:

ERROR in ./node_modules/rxjs/_esm5/observable/BoundNodeCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
at Object.getEffectiveTypeAnnotationNode (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:9341:18)
at assignContextualParameterTypes (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41652:25)
at checkFunctionExpressionOrObjectLiteralMethod (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41948:29)
at checkExpressionWorker (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42959:28)
at checkExpression (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42898:42)
at checkExpressionCached (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42779:38)
at checkReturnStatement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:45418:54)
at checkSourceElement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46763:28)
at Object.forEach (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:1506:30)
at checkBlock (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:44563:16)
at checkSourceElement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46742:28)
at checkFunctionExpressionOrObjectLiteralMethodDeferred (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41990:21)
at checkDeferredNodes (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46828:25)
at checkSourceFileWorker (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46863:17)
at checkSourceFile (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46842:13)
at Object.forEach (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:1506:30)
@ ./node_modules/rxjs/_esm5/observable/bindNodeCallback.js 2:0-76
@ ./node_modules/rxjs/_esm5/add/observable/bindNodeCallback.js
@ ./node_modules/rxjs/_esm5/Rx.js
@ ./node_modules/ng4-geoautocomplete/auto-complete.service.js
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts
ERROR in ./node_modules/rxjs/_esm5/observable/BoundCallbackObservable.js
Module build failed: TypeError: Cannot read property 'type' of undefined
at Object.getEffectiveTypeAnnotationNode (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:9341:18)
at assignContextualParameterTypes (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41652:25)
at checkFunctionExpressionOrObjectLiteralMethod (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41948:29)
at checkExpressionWorker (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42959:28)
at checkExpression (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42898:42)
at checkExpressionCached (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:42779:38)
at checkReturnStatement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:45418:54)
at checkSourceElement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46763:28)
at Object.forEach (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:1506:30)
at checkBlock (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:44563:16)
at checkSourceElement (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46742:28)
at checkFunctionExpressionOrObjectLiteralMethodDeferred (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:41990:21)
at checkDeferredNodes (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46828:25)
at checkSourceFileWorker (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46863:17)
at checkSourceFile (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:46842:13)
at Object.forEach (D:\Documentos\Trabajo\Come\Desarrollo\Mean\node_modules\typescript\lib\typescript.js:1506:30)
@ ./node_modules/rxjs/_esm5/observable/bindCallback.js 2:0-68
@ ./node_modules/rxjs/_esm5/add/observable/bindCallback.js
@ ./node_modules/rxjs/_esm5/Rx.js
@ ./node_modules/ng4-geoautocomplete/auto-complete.service.js
@ ./src/app/app.module.ngfactory.js
@ ./src/main.ts
@ multi ./src/main.ts

How can I solve this problem?
Thanks.

Cannot read property 'referance' of null

Hi,

When selecting an address "1782 U.S. 1" by example, I get this error:

image

image

I saw that this happened sometimes, in different addresses, especially the one who aren't a full address.

Do you know how to fix it?

Thank you for your work.

Have a great day :)

Server side rendering support

Hello i'm using this awesome library for my project but i found one thing that is restricting me to use it further which is server side rendering, how can we make this work with server side rendering (a.k.a Angular Universal). it will be good to have feature.

Validation form problem with delete item

Hi,

I wanted to know if it is possible to handle the click of the delete item(cross) or simply have the same click as the select ?

It's for a form validation.

Have a great day,
Thank you.

Unable to fetch current location.

Thank you for response.

But after deploying my project on server and testing through mobile issue remains.
Unable to get current location even on mobile devices also.

Help me in this since it's a primary role of my project.

Originally posted by @mayank12psingh in #45 (comment)

Restricting Place Types

This is an awesome tool. Thank you for creating it.

Is there any way to restrict the place types as follows?

public userSettings: any = {

showCurrentLocation: false,
showRecentSearch: false,
options: { types: ['(cities)']}

}

api docs

Module not found: Error: Can't resolve 'rxjs/Rx'

Hi,

After Upgrading the Angular & RxJs, ng4-geoautocomplete throws the below error :

ERROR in ./node_modules/ng4-geoautocomplete/auto-complete.service.js
Module not found: Error: Can't resolve 'rxjs/Rx'

Rxjs upgrade has a major impact, Now the import statements have been change.
And that is where the problem lies with ng4-geoautocomplete.

Could you please fix this issue.

Thanks,
Ravi

Get the selected suggestion

Currently, the callback sends the response from the geocode api for a selected suggestion.
There is no way to capture the actual selected suggestion.

In case of some suggestions, the suggestion contains more detail than the returned response from Google.
So, would it be possible to emit/capture the selected suggestion?

clear text from ng4-geoautocomplete

Hi,

I need to clear the text from ng4-geoautocomplete textbox when I click on submit button.
Please help me on how can I achieve this.

Thanks,
suresh

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.