Giter Club home page Giter Club logo

Comments (14)

mayask avatar mayask commented on June 28, 2024 10

@GuelorEmanuel

Look at the way you import the component:

import GooglePlacesAutocomplete from 'react-native-google-places-autocomplete';

It should be imported like this

import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';

from react-native-google-places-autocomplete.

mayask avatar mayask commented on June 28, 2024 2

Hi @davidgruebl @janroures @GuelorEmanuel

Thanks for your feedback. I promise to look at it this weekend.

Max

from react-native-google-places-autocomplete.

janroures avatar janroures commented on June 28, 2024 1

Hm. I just saw in the output that the version of the library is 1.2.2. let me try and downgrade it and I'll come back to you. Thanks.

from react-native-google-places-autocomplete.

davidgruebl avatar davidgruebl commented on June 28, 2024

experiencing the same issue on react-native 0.31.0

from react-native-google-places-autocomplete.

janroures avatar janroures commented on June 28, 2024

getting the same on react native 0.23

from react-native-google-places-autocomplete.

janroures avatar janroures commented on June 28, 2024

@myaskevich in my case it only happens when tapping a list element.

from react-native-google-places-autocomplete.

mayask avatar mayask commented on June 28, 2024

I just looked at it and here's what I got:

The version 1.2+ of this library requires RN v0.28+. Please check your dependencies once again @davidgruebl . Best way to check RN version is to run RN cli command - react-native --version.

from react-native-google-places-autocomplete.

GuelorEmanuel avatar GuelorEmanuel commented on June 28, 2024

@myaskevich
Just checked my version and it's

react-native-cli: 1.0.0
react-native: 0.31.0

from react-native-google-places-autocomplete.

GuelorEmanuel avatar GuelorEmanuel commented on June 28, 2024

@myaskevich
That actually worked, thanks a lot! If you don't mind can you explain the different between the two syntax, why do we need to wrap the name in curly braces?

from react-native-google-places-autocomplete.

mayask avatar mayask commented on June 28, 2024

This is a new ES6 feature called destructing. You can read up on this here. See example:

// module1.js
export const foo = () => {
  console.log('foo');
};
export const bar = () => {
  console.log('bar');
};

// module2.js

// option 1
import module1 from 'module1';
module1.foo() // prints 'foo';

// option2
import { foo } from 'module1';
foo() // prints 'foo';

In order to support the way of importing you proposed, one has to use export default keyword. See below:

// module1.js
export default const foo = () => {
  console.log('foo');
};

// module2.js
import foo from 'module1';

foo(); // prints 'foo'

The reason why we need to do it for now is that because the original library author has put it like this in the first place. I'll probably change it in the future to support that direct import of the component.

from react-native-google-places-autocomplete.

janroures avatar janroures commented on June 28, 2024

That didn't work for me. Using RN 0.23 and 1.1.9 of this library.

Here is my code:

'use strict';

var React = require('react-native');

import Dimensions from 'Dimensions';

import { eventEmitter } from '../utils/EventEmitter';
import {GOOGLE_GEO_APIKEY} from "../config/constants";
import {GooglePlacesAutocomplete} from 'react-native-google-places-autocomplete';

import I18n from 'react-native-i18n';

var {height, width} = Dimensions.get('window');
var pinX = (width/2) - 22.5;
var MapView = require('react-native-maps');
var {
    InteractionManager,
    AsyncStorage,
    TextInput,
    Image,
    StyleSheet,
    Text,
    TouchableOpacity,
    View,
    ListView,
} = React;

export class SecuritySignupLocationMap extends React.Component {

    constructor() {
        super();
        this.state = Store.getState();
        this.state.region = null;
        this.onListTap.bind(this);

        this.pinY = 0;
    }

    componentWillMount() {
        this.locationSelectedEvent = eventEmitter.addListener('locationSelectedEvent', this.save.bind(this));
        this.locationSelectedEventSignup = eventEmitter.addListener('locationSelectedEventSignup', this.saveSignup.bind(this));

        if (this.props.type == "signup") {
            this.pinY = (height/2) - 67.5;
        }else{
            this.pinY = (height/2) - 107.5;
        }
    }

    componentDidMount() {
        InteractionManager.runAfterInteractions(() => {
            this.setState({
                region: {
                    latitude: this.props.latitude,
                    longitude: this.props.longitude,
                    latitudeDelta: 0.005,
                    longitudeDelta: 0.0041
                }
            });
        });
    }

    componentWillUnmount() {
        this.locationSelectedEvent.remove();
        this.locationSelectedEventSignup.remove();
    }

    onRegionChangeComplete(region) {
        this.setState({
            region: region
        });
    }

    save() {
        var location = {
            latitude: this.state.region.latitude,
            longitude: this.state.region.longitude
        }
        Actions.fetchAddressForLocation(location);
        NavActions.back();
    }

    saveSignup() {
        var location = {
            latitude: this.state.region.latitude,
            longitude: this.state.region.longitude
        }
        Actions.fetchAddressForLocation(location);
        Actions.back();

    }

    onListTap(location) {
        var longitude = location.geometry.location.lng;
        var latitude = location.geometry.location.lat;

        var region = {
            latitude: latitude,
            longitude: longitude,
            latitudeDelta: this.state.region.latitudeDelta,
            longitudeDelta: this.state.region.longitudeDelta
        };

        this.refs.map.animateToRegion(region);
        this.state.region = region;
    }

    render() {
        if (this.state.region) {
            return (
              <View ref='view'>
                <MapView
                ref='map'
                    style={styles.map}
                    initialRegion={{
                    latitude: this.state.region.latitude,
                    longitude: this.state.region.longitude,
                    latitudeDelta: this.state.region.latitudeDelta,
                    longitudeDelta: this.state.region.longitudeDelta
                }}
                region={this.state.region}
                onRegionChangeComplete={this.onRegionChangeComplete.bind(this)}>

                </MapView>
                <Image
                    style={[styles.icon, {top: this.pinY}]}
                    source={require('../images/mapPinIcon.png')}
                />
                <GooglePlacesAutocomplete
                    placeholder={I18n.t('search')}
                    minLength={2} // minimum length of text to search
                    autoFocus={false}
                    fetchDetails={true}
                    onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true
                      this.onListTap(details);
                    }}
                    getDefaultValue={() => {
                      return this.props.text; // text input default value
                    }}
                    query={{
                      // available options: https://developers.google.com/places/web-service/autocomplete
                      key: GOOGLE_GEO_APIKEY,
                      language: 'es', // language of the results
                     // types: '(cities)', // default: 'geocode'
                    }}
                    styles={{
                      description: {
                        fontWeight: 'bold',
                      },
                      predefinedPlacesDescription: {
                        color: '#1faadb',
                      },
                      container: {
                        flex:1,
                        position:'absolute',
                        top:0,
                        left:0,
                        right:0,
                      },
                      textInput: {
                        flex:1,
                        flexDirection: 'row',
                        textAlign:'left',
                        paddingLeft:10,
                        paddingRight:10,
                        marginTop:10,
                        marginLeft:10,
                        marginRight: 10,
                        height:40,
                        // borderWidth:1,
                        // borderColor:'transparent',
                        backgroundColor:'white',
                        opacity:0.9,
                      },
                      textInputContainer:{
                        backgroundColor: 'transparent',
                        borderTopWidth: 0,
                        borderBottomWidth: 0
                      },
                      separator:{
                        height: 0
                      },
                      listView: {
                        backgroundColor:'white',
                        opacity:0.9,
                        marginLeft: 10,
                        marginRight: 10,
                      }
                    }}
                    currentLocation={true} // Will add a 'Current location' button at the top of the predefined places list
                    currentLocationLabel="Current location"
                    nearbyPlacesAPI='GooglePlacesSearch' // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
                    GoogleReverseGeocodingQuery={{
                      // available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
                    }}
                    GooglePlacesSearchQuery={{
                      // available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
                      rankby: 'distance',
                    }}
                    filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
                    enablePoweredByContainer={false}
                  />
              </View>
            );
        }else{
            return(<Text>{I18n.t('loading')}</Text>);
        }
    }
}

Error message: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of StaticRenderer.

from react-native-google-places-autocomplete.

mayask avatar mayask commented on June 28, 2024

@janroures Can you capture the output after running npm ls --depth=0 inside your project and paste here as a gist?

from react-native-google-places-autocomplete.

mayask avatar mayask commented on June 28, 2024

@janroures GOTCHA!

from react-native-google-places-autocomplete.

GuelorEmanuel avatar GuelorEmanuel commented on June 28, 2024

@myaskevich
Thanks for the detail explanation.

from react-native-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.