FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

[question] How to default a previously stored location fetched with GooglePlacesWidget ? #108

Open eliasturbay opened 7 years ago

eliasturbay commented 7 years ago

I'm trying to implement an Edit form, and one of the fields is a Location that was previously fetched using the GooglePlacesWidget. In the create form, the value for that field is:

{
        "name": "1978 65th St, Brooklyn, NY 11204, USA",
        "placeId": "ChIJ22oJeh9FwokRjvrpcv_qFm8",
        "details": {
            "address_components": [{
                "long_name": "1978",
                "short_name": "1978",
                "types": ["street_number"]
            }, {
                "long_name": "65th Street",
                "short_name": "65th St",
                "types": ["route"]
            }, {
                "long_name": "Bensonhurst",
                "short_name": "Bensonhurst",
                "types": ["neighborhood", "political"]
            }, {
                "long_name": "Brooklyn",
                "short_name": "Brooklyn",
                "types": ["sublocality_level_1", "sublocality", "political"]
            }, {
                "long_name": "Kings County",
                "short_name": "Kings County",
                "types": ["administrative_area_level_2", "political"]
            }, {
                "long_name": "New York",
                "short_name": "NY",
                "types": ["administrative_area_level_1", "political"]
            }, {
                "long_name": "United States",
                "short_name": "US",
                "types": ["country", "political"]
            }, {
                "long_name": "11204",
                "short_name": "11204",
                "types": ["postal_code"]
            }, {
                "long_name": "3814",
                "short_name": "3814",
                "types": ["postal_code_suffix"]
            }],
            "adr_address": "<span class=\"street-address\">1978 65th St</span>, <span class=\"locality\">Brooklyn</span>, <span class=\"region\">NY</span> <span class=\"postal-code\">11204-3814</span>, <span class=\"country-name\">USA</span>",
            "formatted_address": "1978 65th St, Brooklyn, NY 11204, USA",
            "geometry": {
                "location": {
                    "lat": 40.61648699999999,
                    "lng": -73.986372
                },
                "viewport": {
                    "northeast": {
                        "lat": 40.61794133029149,
                        "lng": -73.98491276970849
                    },
                    "southwest": {
                        "lat": 40.61524336970849,
                        "lng": -73.98761073029151
                    }
                }
            },
            "icon": "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
            "id": "44d7e28f7c7fbd69052acef1988597f3c252e00f",
            "name": "1978 65th St",
            "place_id": "ChIJ22oJeh9FwokRjvrpcv_qFm8",
            "reference": "CmRbAAAAfJgMt2BlJwU-DG2BtlptqaTFIWKinsfrSdsXjEiueA2kD5I_UqiuLmFKTmmyGxL8mpbo3cwhErPiiiPsxKGOoRzbBTRWLLCBVdSxRmtJnecp90HdmXRny5KKbLhaeFjEEhCg1T9QZcJnMjs7aHbxDBiDGhTt64PnsaBF76Em9ZWLuZFSm5gNVw",
            "scope": "GOOGLE",
            "types": ["street_address"],
            "url": "https://maps.google.com/?q=1978+65th+St,+Brooklyn,+NY+11204,+USA&ftid=0x89c2451f7a096adb:0x6f16eaff72e9fa8e",
            "utc_offset": -240,
            "vicinity": "Brooklyn"
        },
        "loc": [-73.986372, 40.61648699999999],
        "types": ["street_address"]
    }

So, to default that value in the Edit form I tried something like:

        myDefaults.locationAddress = {
          name: `${locationName.name}, ${locationName.city}, ${locationName.region} ${locationName.postalCode}`,
          details: {
            geometry: {
              location: {
                latitude: listing.lat,
                longitude: listing.lng
              }
            }
          }
        };

but it didn't worked, and I can't find a proper way to make it. Can someone help me with that?

Thanks in advance!

eliasturbay commented 7 years ago

@FaridSafi @cooperka any clue on how to approach this thing? Basically the question is how to default a proper value for the GooglePlacesWidget... For proper I mean that it should display the formatted address in the form and also store the coordinates (lat and long) as if it would be populated by the User. Thanks in advance and sorry to bother you!