XF 2.1 How to get userField location?

mcatze

Well-known member
I try to create a membermap und want to use the 'location'-field. Now i try to fetch this field within my addon.
I am a newby with XF2.1 coding and hope someone can explain me a little bit more which way i should go.

At the moment i have a js template for createMap and now i need the location field data. I would try to set for each member how filled this field a marker at the map.
 
Problem is: Location fields can be anything the user writes in it. So you cannot depend on it to show a real location for a map.

Even IF there is a real location in the location field, you need to convert it to geo coordinates to use it for a map. There are utilities to convert ip addresses to geo locations, but beside of Geonames (which costs money) I do not know any tool to convert location names to geo data.
 
Assuming you have the user entity (XF\Entity\User $user), you can access it via the Profile relation $user->Profile->location. Make sure to preload the relation in your finder or you'll cause a database query per user ($finder->with('Profile')).
 
Top Bottom