• Resolved jeroenm77

    (@jeroenm77)


    I have just installed version 1.9-rc1 and have been able to use the multiple markers plugin provided in this version.

    For my site I have a marker for each lawyer in a certain area. When two lawyers happen to work at the same location only one markers shows up (or the markers turns blue and shows a number 2 in the circle to indicate that there are multiple lawyers at this location.) What my client wants is that when you reach the highest zoom level that you can see the individual placemarks so you can click on each one instead of only the top one.

    To do this I thought I’d create a function in functions.php and compare the coordinates. If both latitude and longitude are identical I can add a small offset to one of the markers to slightly move them on the map. Unfortunately I haven’t been able to get this working.

    Is there an easier solution?

    http://wordpress.org/extend/plugins/basic-google-maps-placemarks/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jeroenm77

    (@jeroenm77)

    Any ideas on this one please?

    Plugin Author Ian Dunn

    (@iandunn)

    That’s not something the plugin supports, but a Google search turned up these:

    You might also want to try looking at http://automattic.com/map/ and zooming into cities like Portland and San Francisco. View the source to see how they get them spread out.

    If you get it working, please post a link to the code here so that others can use it too.

    Thread Starter jeroenm77

    (@jeroenm77)

    Thanks a lot, that gave me some ideas.

    I have added this function to my themes functions.php file:

    function addBGMPOffsetOnDuplicates( $placemarks )
    {
    	//	Todo: store the coordinates in an array and search through that. Tried it, didn't work, the search came up empty every time.
    
        $newPlacemarks = array();
    
    	$doneCoordinates = ""; //Store coordinates we have checked out
    
    	foreach( $placemarks as $placemark )
    	{
    		$coordinates = $placemark['latitude'] . $placemark['longitude']; //Get the coordinates x and y set
    
    		while (substr_count($doneCoordinates, $coordinates) > 0)			// Do these coords exist in our buffer?
    		{
    			$longitude = (double)$placemark['longitude'];
    			if (is_float($longitude))
    			{
    				$longitude -= 0.0000030;							//Add offset
    				$placemark['longitude'] = strval($longitude);
    			}
    
    			$latitude = (double)$placemark['latitude'];
    			if (is_float($latitude))
    			{
    				$latitude -= 0.0000030;								//Add offset
    				$placemark['latitude'] = strval($latitude);
    			}
    
    			$coordinates = $placemark['latitude'] . $placemark['longitude']; //Get the coordinates x and y set again, the correct location might exist as well
    		}
    
    		$doneCoordinates .= $coordinates;							//Add the processed coordinates to our buffer
    
    		$newPlacemarks[] = $placemark;								//Add the corrected placemark to the output array
    	}
    
    	return $newPlacemarks;
    }
    
    add_filter( 'bgmp_get-map-placemarks-return', 'addBGMPOffsetOnDuplicates' );

    While it works, it still leaves a lot to be desired, but I can’t seem to get it working with array_search or something similar. So now quick and dirty.

    Also I noticed if I have a - in my placemark title it gets replaced with & #8211;. This happened since I added my functions, but it might also be a result of installing version 1.10 of the BGMP addon (used to work with 1.9rc).

    Happy Easter!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add offset to a marker when multiple markers are on same coordinates.’ is closed to new replies.