Client Map View with Nominatim and Custom Fields

This is the way I’ve created my Client Map View once I’ve stored the coordenates for every address on the client custom fields.

You can achieve this just with the DEFAULT ADDRESS by REVERSE GEOCODING.
I prefer this method as I think is faster and cleaner.

1- I’m assuming you READ the topic Autofill Client Address + Client Map with Google Map API (includes trace route) so you have created 2 custom fields where you store the lat,lng for your client addresses.

2- Download this file 2.5 KB file on MEGA

3- OPEN the file Application > Modules > Clients > Views > clientMap.php and change the coordenates to setup your view -33.273690, 151.484360.

4- UPLOAD THE FILE clientMap.php to Application > Modules > Clients > Views

5- OPEN Application > Modules > Clients > Views > index.php
AFTER <?php $this->layout->load_view('clients/partial_client_table'); ?>
PASTE <?php $this->layout->load_view('clients/clientMap'); ?>

Hope you found the topic helpful!

NOTE: Now that you have the Client Map View you can achieve more things, for example, draw polygons for every client region: get the boundaries with Nominatin search.php?q=<?php _htmlsc($client->client_city); ?><?php _htmlsc($client->client_postcode); ?><?php _htmlsc($client->client_state); ?>&polygon_geojson=1&format=json then draw it on the map.

LET’S DRAW POLYGONS TO TRACE ROUTES E.G.

 <?php if((!empty($custom_fields['client']['Latitude'])) && (!empty($custom_fields['client']['Longitude']))){ ?>
		const polygon<?php echo $i; ?> = {
  type: "Polygon",
  coordinates: [[[<?php echo nl2br($custom_fields['client']['Longitude']); ?>,<?php echo nl2br($custom_fields['client']['Latitude']); ?>],[151.484360,-33.273690]]]
	};
	const layer<?php echo $i; ?> = L.geoJSON(polygon<?php echo $i; ?>);
	layer<?php echo $i; ?>.setStyle({ weight: "5", color: '#1DA1F2' });
	map.addLayer(layer<?php echo $i; ?>);
	map.fitBounds(layer<?php echo $i; ?>.getBounds());			 			
 <?php }  ?>

LET’S GET THE INFO FROM THE DATABASE TO MAKE A FRONTEND MAP
My client_address_2 = “City Postcode State”
My client_custom_fieldid = 8 es LATITUDE
My client_custom_fieldid = 9 es LONGITUDE

SELECT ip_clients.client_id,ip_clients.client_address_2,GROUP_CONCAT(ip_client_custom.client_custom_fieldvalue SEPARATOR ', ') AS 'lat,lng' FROM ip_clients,ip_client_custom WHERE ip_clients.client_id = ip_client_custom.client_id AND ip_clients.client_address_2 != '' AND ip_client_custom.client_custom_fieldid = '8' AND ip_client_custom.client_custom_fieldvalue IS NOT NULL OR ip_clients.client_id = ip_client_custom.client_id AND ip_clients.client_address_2 != '' AND ip_client_custom.client_custom_fieldid = '9' AND ip_client_custom.client_custom_fieldvalue IS NOT NULL GROUP BY ip_clients.client_id;