I currently use the Google Maps Places API to get location information. However, in my application, the locality is not always correct. As in, Zillow and the local property appraiser list the address differently. For example:
Google Maps Address:
3041 NW 10th Ct, Fort Lauderdale, FL 33311
The Local Property Appraiser Address:
3041 NW 10 COURT UNINCORPORATED, 33311
*the “UNINCORPORATED” part is the most important piece of this that I need right.
Long story short I have all of the locality data, and I would like to query a custom Google MyMaps, and use the data in MyMaps to override the Google Maps Places API (Example Link).
The following is my current function for capturing “addressComponents”.
async function getPlaceDetails(placeId) {
const { Place } = await window.google.maps.importLibrary("places");
const place = new Place({
id: placeId,
requestedLanguage: "en", // optional
});
// Call fetchFields, passing the desired data fields.
await place.fetchFields({
fields: ["addressComponents", "formattedAddress", "location"],
});
// console.log(place);
const usefulComponents = {
"id": placeId,
"location": {
"lat": place.Fg.location.lat,
"lng": place.Fg.location.lng
},
"formattedAddress": place.formattedAddress,
"addressComponents": {
"street_number": "", // street number
"route": "", // street
"locality": "", // city // THIS IS WHAT I WOULD LIKE TO REPLACE.
"administrative_area_level_2": "", // county
"administrative_area_level_1": "", // State
"country": "", // country
"postal_code": "", // zip code
"postal_code_suffix": "" // zip code suffix
}
};
place.addressComponents.forEach(item => {
if (usefulComponents["addressComponents"].hasOwnProperty(item.types[0])) {
usefulComponents["addressComponents"][item.types[0]] = item.longText;
}
});
// console.log(usefulComponents);
return usefulComponents; // Return the useful components
}
I have been doing this so far by geocoding the address, and then searching through GeoJSON I have locally. However, if I could do all of this through an API it would be a lot cleaner of a solution. There are more complicated aspects of this that would make this solution be more favorable.