Good information in AlanDB's post above.
If you can afford one, I recommend a higher end handheld GPS like Garmin's Montana or Oregon series. New, these devices are in the $500 range but bargains can be found on eBay. As Alan mentioned, you can also save a few $$ by shopping out a refurbished unit. If you go that route, make sure you get a factory refurbished model with warranty.
I've owned dozens of handheld GPS devices over the years and as is the case with many other products, you get what you pay for. The cheaper GPS models I've tried always seem to lack features I wish it had. Garmin has a great web page that lets you compare the features of various models :
https://buy.garmin.com/en-US/US/c12521-p0.html
In my case, I use both a Garmin Montana 650T and an Oregon 650. My aging eyes like the Montana's 4 inch glove friendly touch screen which can be set to display larger numerals. I use the Oregon as a second unit to display a topo map. This eliminates the need to constantly switch screens while riding. I also use a smartphone on occasion and it works well as a second unit but can be troublesome to operate while riding due to icon sizes and screen sensitivity.
Of course it all depends on what level of detail you want to see on the screen and record for your rides. An entry level GPS or smartphone may suit your needs if all you want are basic parameters such as time, distance, elevation, track etc. A higher end unit will provide things like a larger screen, the ability to display many stats in any order, the ability to receive data from remote sensors like temperature, heart rate, and many others.
Whatever unit you choose, I recommend one that uses field replaceable AA batteries. GPS units are notorious power hogs and unless you install fresh ones before every ride, seem to die on you when you least expect it. I use Eneloop rechargeable AA batteries in all my handhelds and carry spares in my pocket.
GPS apps on a smartphone can exhaust its battery fairly quickly. If you go that route, be mindful of the charge level. A dead battery in a GPS during a ride is annoying but a dead smartphone could be life threatening if injured or during a medical emergency. Carrying a cable which will charge your phone from the ebike battery is a good idea.
RAM makes a line of quality handlebar mounts and cradles for many smartphones and GPS units.
https://www.rammount.com/activity/bike-mounts . I use the U bolt style which solidly holds devices weighing up to 5 pounds.
There are a lot of products out there. The trick is to find those that suit your needs without breaking the bank.
Good luck!