{"id":274428,"date":"2018-08-06T06:51:38","date_gmt":"2018-08-06T13:51:38","guid":{"rendered":"http:\/\/css-tricks.com\/?p=274428"},"modified":"2018-08-06T06:51:38","modified_gmt":"2018-08-06T13:51:38","slug":"lets-make-a-form-that-puts-current-location-to-use-in-a-map","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/lets-make-a-form-that-puts-current-location-to-use-in-a-map\/","title":{"rendered":"Let’s make a form that puts current location to use in a map!"},"content":{"rendered":"
I love shopping online. I can find what I need and get most things for a decent price. I am Nigerian currently working and studying in India, and two things I dread when shopping online are:<\/p>\n
Maybe I\u2019m just lazy, but these things are not without challenges! For the first one, thanks to payment processing services like PayPal and e-wallets, I neither have to type in my 12-digit credit card number for every new e-commerce site I visit, nor have to save my credit card details with them.<\/p>\n
For the second, the only time-saving option given by most shopping websites is to save your shipping address, but you still have to fill the form (arrghh!). This is where the challenge is. I’ve had most of my orders returned because my address (which I thought<\/em> was the right address) could not be located or confirmed by the app for one reason or another.<\/p>\n <\/p>\n Getting a user’s address through an input form is a clean solution but can also be a herculean task to the user. Here’s why:<\/p>\n Getting the user’s address by the tap\/click of a button. Yup, that’s easy! The UX is great as it saves the user both the time and effort of filling out some form. It will also save the store owner time, effort, and even money in some cases, as there’ll likely be a reduction in the number of incorrectly placed orders or shipments. <\/p>\n Let\u2019s build a mini app that gets a user’s address and shows it on a Google Map interface using vanilla JavaScript. The concept is as follows:<\/p>\n To build this app, we\u2019re going to use the Materialize CSS framework to save us some time fussing with styles. Materialize is a modern responsive front-end framework based on Google\u2019s Material Design system<\/a>. The beta version<\/a> works with vanilla JavaScript.<\/p>\n A basic setup using Materialize\u2019s CSS and JavaScript files in a document is like this:<\/p>\n We\u2019re also going to use the Google Maps API for displaying the map and getting the user’s human-readable address. We\u2019ll need an API key to do this. Here\u2019s how to get one:<\/p>\nAddress inputs are challenging<\/h3>\n
\n
A potential solution: get the address automatically<\/h3>\n
\n
Getting started and setting up<\/h3>\n
<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>Address Locator<\/title>\r\n <link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/materialize\/1.0.0-beta\/css\/materialize.min.css\">\r\n <link rel=\"stylesheet\" href=\"css\/main.css\">\r\n<\/head>\r\n<body>\r\n <script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/materialize\/1.0.0-beta\/js\/materialize.min.js\"><\/script>\r\n <script src=\"js\/main.js\"><\/script>\r\n<\/body>\r\n<\/html><\/code><\/pre>\n