Giter VIP home page Giter VIP logo

cordova-plugin-googleplaces's Introduction

cordova-plugin-googleplace

A Cordova plugin to use the Google Places SDK.

NOTE: this is a preliminary version, as of now only iOS is supported and Android is in the making

Getting Started

This plugin allows to user the Google Places SDK from Cordova, for building autocomplete UIs for locations.

Installing

$ SHELL COMMAND TO INSTALL
$ cordova plugin add cordova-plugin-googleplaces --variable API_KEY_FOR_IOS="XXXX"

Usage

For more details you can generate the Javascript docs with yarn doc:

$ yarn doc
yarn run v1.1.0
$ docco www/GooglePlaces.js
docco: www/GooglePlaces.js -> docs/GooglePlaces.html

currentPlace

You can call the currentPlace method to find information on the current locatoin.

This method requires that the user has enabled geolocation in the app. To to so, use cordova-plugin-geolocation (or equivalent) before calling this method.

// Authorize access to the current position using cordova-plugin-geolocation
navigator.geolocation.getCurrentPosition(function(pos) {

  // retreive the current place
  cordova.plugins.GooglePlaces.currentPlace(
    // place contains the API result
    place => {
      console.log(place);
      //   {
      //    place: {
      //      name: "some place name",
      //      placeID: "XXXXX"
      //    },
      //    likehood: 0.87 // <= means 87% accurate
      //   }
    },
    err => console.log(err)
  );
});

autocompleteQuery

The autocompleteQuery(query, [bounds], [filter], success, failure) method find candidates ("predictions") given an input query string:

cordova.plugins.GooglePlaces.autocompleteQuery("22 some random address",
  // results contains an array of predictions, the first being the most pobable
  results => {
    console.log(res);
    //   {
    //     fullText: "description of the place",
    //     primaryText: "partial description of the place",
    //     secondaryText: "partial description of the place",
    //     placeID: "XXXXX",
    //     types: [ "a", "list", "of", "types", "for", "the", "result" ]
    //   }
  },
  err => console.log(err),
);

This method can take optional arguments:

  • bounds defines a regions to limit the search to.

    It should be defined as a "coordinate region" object such as:

    {
     northEast: {
       latitude: 1.234,
       longitude: 5,667
     },
     southWest: {
       latitude: 1.234,
       longitude: 5,667
     }
    }
  • filter defines a filter to limit the results to a specific region.

    Such a filter is given by a filter type taken from the GooglePlaces.AutocompleteFilterTypes and an (optional) country:

    {
      filter: google.plugins.GooglePlaces.AutocompleteFilterTypes.NoFilter,
      country: "FR" // <= this is optional
    }

    Several values are available for the filter type:

    • AutocompleteFilterTypes.NoFilter is an empty filter; all results are returned.
    • AutocompleteFilterTypes.Geocode returns only autocomplete results with a precise address. Use this type when you know the user is looking for a fully specified address.
    • AutocompleteFilterTypes.Address returns only places that are businesses.
    • AutocompleteFilterTypes.Establishment returns only places that are businesses.
    • AutocompleteFilterTypes.Region returns only places that match one of the following types: locality, sublocality, postal_code, country, administrative_area_level_1, administrative_area_level_2
    • AutocompleteFilterTypes.City returns only results matching locality or administrative_area_level_3.

pickPlace

pickplace([bounds], success, [failure]) displays the native UI for picking a nearby place.

This method requires that the user has enabled geolocation in the app. To to so, use cordova-plugin-geolocation (or equivalent) before calling this method.

cordova.plugins.GooglePlaces.pickPlace(
  // place contains complete place information on the selected target
  place => {
    console.log(res);
    //   {
    //      name: "some place name",
    //      placeID: "XXXXX",
    //      // and lots of other fields, depending on the place info available
    //   }
  },
  err => console.log(err),
);

The optional bounds argument is defined as explained above:

{
 northEast: {
   latitude: 1.234,
   longitude: 5,667
 },
 southWest: {
   latitude: 1.234,
   longitude: 5,667
 }
}

showPlaceAutocomplete

Displays the native UI for place autocompletion.

cordova.plugins.GooglePlaces.showPlaceAutocomplete(
  // place contains complete place information on the selected target
  place => {
    console.log(res);
    //   {
    //      name: "some place name",
    //      placeID: "XXXXX",
    //      // and lots of other fields, depending on the place info available
    //   }
  },
  err => console.log(err),
);

Contributing

Feel free to contribute anytime !

License

This project is licensed under the MIT License - see the LICENSE file for details

TODO

  • Add Android support

cordova-plugin-googleplaces's People

Contributors

aurelien-iapp avatar moczniak avatar ushu avatar xavier-iapp avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

cordova-plugin-googleplaces's Issues

JSON Error

Hi, I'm trying to use autocomplete feature on android but java code returns invalid json

Error: JSON error
    at f (GooglePlaces.dist.js:2)
    at Object.callbackFromNative (cordova.js:295)
    at processMessage (cordova.js:1119)
    at processMessages (cordova.js:1142)

Cordova callback returns error so i think there is an error on java code, didn't inspect it yet

ios build error

ionic cordova build ios returned error:

Error: Error code 65 for command: xcodebuild with args: -xcconfig,/Users/user/Documents/git/pj/2.x/myApp_2.0.0_dev/platforms/ios/cordova/build-debug.xcconfig,-workspace,myApp Live.xcworkspace,-scheme,myApp Live,-configuration,Debug,-sdk,iphonesimulator,-destination,platform=iOS Simulator,name=iPhone X,build,CONFIGURATION_BUILD_DIR=/Users/user/Documents/git/pj/2.x/myApp_2.0.0_dev/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/user/Documents/git/pj/2.x/myApp_2.0.0_dev/platforms/ios/build/sharedpch

$ ionic info

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.9
Cordova Platforms  : android 6.3.0 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

ios-deploy : 1.9.2
ios-sim    : 5.0.6
Node       : v8.11.1
npm        : 5.6.0
OS         : macOS Sierra
Xcode      : Xcode 9.2 Build version 9C40b

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

autocompleteQuery errors at new Error

I am trying to run the autocompleteQuery method, but it doesn't work.

cordova.plugins.GooglePlaces.autocompleteQuery(addresses[0]["extra"]["lines"].join(", "), results => {
  console.log(results);
});

in which addresses[0]["extra"]["lines"] is an array of different parts of an address.

it blocks at return o[1](new Error(e)) and error is o[1] is not a function. (In 'o[1](new Error(e))', 'o[1]' is undefined)

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.