Jump to content

Map Marker Map


ryan

Recommended Posts

OK, I need some help with this. This is my setup:

Dealers

-Australia

--Dealer 1

--Dealer 2

I would like a map on the Dealers page showing a marker for each dealer. Is there a way to have the marker link go to an anchor tag I have set for the country heading on the same page?

echo "<div id='map'></div>"; //div to show in template map

$js = "<script type='text/javascript'>";
$js .= "RCDMap.options.mapTypeId = google.maps.MapTypeId.ROADMAP;";
$js .= "\nRCDMap.init('map', 0, 0);";

$dealers = $pages->get("/dealers/")->find("template=dealer");
foreach($dealers as $marker) {
$js .= "\nRCDMap.addMarker('{$marker->title}', '{$marker->url}', {$marker->map_marker->lat}, {$marker->map_marker->lng});";
}
$js .= "\nRCDMap.fitToMarkers();";
$js .= "</script>";
echo $js;
Link to comment
Share on other sites

It should be that second argument to RCDMap.addMarker, where you could specify whatever URL (or anchor) you want:

RCDMap.addMarker('some title', '/some/url/', lat, lng);

RCDMap.addMarker('some title', '#some_anchor', lat, lng); 
Link to comment
Share on other sites

Ugh, thanks Ryan, it seems so obvious now....in my defence, it was late last night I posted that.

Although how would I grab the anchor link of the parent of each marker i.e. #australia rather than #dealer1?

Edit: Got it!

$js .= "\nRCDMap.addMarker('{$marker->title}', '#{$marker->parent->title}', {$marker->map_marker->lat}, {$marker->map_marker->lng});";
Link to comment
Share on other sites

Another factor is that I don't think the MapMarker works when placed in other tabs. I think gmaps probably just needs to be visible when the editor is rendered in order for everything to work optimally.

Link to comment
Share on other sites

Yep, there is a problem when gmap is hidden. This happened to me on the frontend of a site where I was using jqueryUi to show the map, and apparently it's very common with lightboxes. The problem is that, if you are using display: none; to hide the map, it first gets rendered with 0px size, and this is what jquery's .hide() uses. The solution would be to use visibility:hidden; or position it absolutely outside of the screen instead. But I think this wouldn't be easy to do in the admin, since it's using jqueryUi...

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

I have recently also a problem with the plugin. The address will not be geocoded.

How can I set the value status from my own form?

$mitgliedPage->geocode->address = $form['strasse'].', '.$form['plz'].' '.$form['ort'];
$mitgliedPage->geocode->status = ...?

Thank you for your help and the great work here!

Link to comment
Share on other sites

To Geocode from the API side, you need to set the address field and save the page:

$page->map->address = '411 Holly Road, Hopkins, MN';
$page->save();

If that doesn't do it, you may sometimes need to give $page a hint:

$page->trackChange('map');
$page->save();

If it still doesn't work, you might want to double check that your PHP install supports allow_url_fopen.

The 'status' field is not meant to be set by you. It is set by Google Maps geocoder.

Link to comment
Share on other sites

ryan - this is an amazing module! I'm just using it on a website I'm building and it is spot on :)

Just a note to others: I originally had a separate Address field, but you don't need that with this module. I wasn't sure how much you could customise the address input, but you can do whatever you like within reason.

What I mean is Google is pretty forgiving - you can put things like "Somewhere over the rainbow, Rydal, Ambleside, LA22 9LX" then it will just take the parts of the address it understands and find the location from that which essentially allows you to begin the address however you like (useful if you want to put a specific brand name or other title in there at the beginning). What you can't then do of course is drag and drop the pin as the address changes again, but so far the pins have been spot on for me since they're using UK postcodes and I'm picking items in the wilderness for now.

I've also been putting commas in so that when I output the address on the page it can do a new line in the address based on the commas.

  • Like 1
Link to comment
Share on other sites

I've also been putting commas in so that when I output the address on the page it can do a new line in the address based on the commas.

Thanks, Pete. You just saved me a load of work. (Why didn't I think of that?)

Link to comment
Share on other sites

What you can't then do of course is drag and drop the pin as the address changes again, but so far the pins have been spot on for me since they're using UK postcodes and I'm picking items in the wilderness for now.

If you uncheck the checkbox separating the address and the lat/lng boxes, you can adjust the coordinates separately from the address, or vice versa.

  • Like 1
Link to comment
Share on other sites

The above uses my RCDMap class. Feel free to grab it if you find it helpful. You'll want to view the source on any of those URLs above to see how it works. http://www.di.net/al...ripts/RCDMap.js

An addition to the RCDMap.js to contol the zoom level if there's only one marker ( ryan script needs at least 2 markers to set the zoom level, wich is nice if you've more then one marker )

Just replace the fitToMarkers at the bottom of the script & it wil work for 1 marker with zoom level 10, or the zoom level depending on multiple markers.

fitToMarkers: function() {
   if(RCDMap.numMarkers == 1 ) {
       RCDMap.map.setZoom(10);
   } else {
       var bounds = new google.maps.LatLngBounds();
       for(var i = 0; i < RCDMap.numMarkers; i++) {
           var latLng = RCDMap.markers[i].position;
           bounds.extend(latLng);
       }
       RCDMap.map.fitBounds(bounds);
   }
}
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi ryan

Just tried to integrate the MapMarker address field with search and it won't let me. Am I doing something wrong?

My selector is as follows:

$matches = $pages->find("map_marker.address%=$q, limit=50"); 

I think I might just be being thick :)

Link to comment
Share on other sites

FieldtypeMapMarker doesn't implement a getMatchQuery method, which is required in order to support any operators that don't exist in MySQL. For instance, MySQL knows what "=" and ">" are, but it doesn't know what "%=" is. So I'm guessing you are getting a "Operator '%=' is not implemented in FieldtypeMapMarker" error message.

The second issue is that there isn't actually a field named 'address' in the DB, as this fieldtype represents it with the default 'data' field. Meaning you would just refer to it as "map_marker" (or whatever you field name is) rather than "map_marker.address". But the truth is, since we're using 'address' as in this Fieldtype at runtime, we really should allow it for queries too. Try adding this to your FieldtypeMapMarker.module, which should solve both issues: 

public function getMatchQuery($query, $table, $subfield, $operator, $value) {
  if(!$subfield || $subfield == 'address') $subfield = 'data';
  if($operator != '%=') return parent::getMatchQuery($query, $table, $subfield, $operator, $value); 
  $ft = new DatabaseQuerySelectFulltext($query);
  $ft->match($table, $subfield, $operator, $value);
  return $query;
}
Let me know if that works out for you, and I'll add it to mine too. I'm also going to add a fulltext index to the 'data' field so that we can use other partial match operators. 
 
Link to comment
Share on other sites

Ah, except I have two issues that I suspect are more general Selector issues.

If I'm searching for the partial word "test" but the actual word is "testing" for example, it won't return a result. I thought it might be a length limitation, but I even tried "testin" without the G and it doesn't work no matter which selector I try. :(

The other issue is postcodes. I have a post code (zip code) in the map marker field that goes something like "LA22 X99". Typing in either LA22 or X99 returns nothing :( Is it possible they're too short? I seem to remember something about mySQL defaults limiting short word searches so this one might not be a bug :)

Link to comment
Share on other sites

I think Soma's right. The %= selector works for postcodes and part postcodes cos it doesn't use the fulltext index. It's a bit less versatile than a fulltext search and it is a bit slower but I have it searching about 7000 pages with no noticeable speed issues. (Even 'slow' mySQL is still fast.)

Link to comment
Share on other sites

If I'm searching for the partial word "test" but the actual word is "testing" for example, it won't return a result. I thought it might be a length limitation, but I even tried "testin" without the G and it doesn't work no matter which selector I try.

Since it's using LIKE in this case (rather than fulltext) it won't matter. 

I just tested it out here on the skyscrapers profile. These queries worked for me:

$pages->find("map.address%=peachtree"); // returned all skyscrapers on peachtree road
$pages->find("map.address%=pea"); // returned the same thing
$pages->find("map.address%=191"); // Returned "191 peachtree road" skyscraper

Try grabbing the latest version of FieldtypeMapMarker. I updated it to have the new getMatchQuery method. I also modified it a bit so that it supports ^= and $=, and all the fulltext searching operators. Though the fulltext operators will only work on newly created fields, since existing installs won't have a fulltext index. But like DaveP said, you'd have to have a very large quantity of items before you'd see the speed difference. 

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

Hi!

I just came across a strange problem and I hope you can help me. It's something that worked before, but suddenly stopped working. As far as I know I did not change the code in any way,

Ok, here we go:

I use an older version of this module and the module itself works perfectly fine. I use it together with Ryan's RCDMap class (for Google Maps) and the source code generated using the module is:

<script type='text/javascript'>
RCDMap.options.zoom = 4;
RCDMap.options.mapTypeId = google.maps.MapTypeId.HYBRID;
RCDMap.init('map', 60.128162,18.643501);

RCDMap.addMarker('Fotografiska Museet', '/bezienswaardigheden-en-attracties/fotografiska-museet/', 59.319450, 18.077618, 'FFFF00','A');
RCDMap.addMarker('Koninklijk paleis', '/bezienswaardigheden-en-attracties/koninklijk-paleis/', 59.326756, 18.071651, 'FFFF00','B');
RCDMap.addMarker('Skälby', '/bezienswaardigheden-en-attracties/skalby/', 56.682201, 16.336901, 'FF0000','C');
RCDMap.addMarker('Finspångs Slott', '/bezienswaardigheden-en-attracties/finsp-ngs-slott/', 58.709824, 15.770853, 'FF0000','D');
RCDMap.addMarker('Brudfjällsvägen', '/bezienswaardigheden-en-attracties/brudfjallsvagen/', 58.860771, 12.401965, 'FF0000','E');
RCDMap.fitToMarkers();</script>
 

So far no problems...

The RCDMap.addMarker function is:

	addMarker: function(title, url, lat, lng, poicolor, poi_id) {

		var latLng = new google.maps.LatLng(lat, lng);
		
		var marker = new StyledMarker({ 
			styleIcon:new StyledIcon(StyledIconTypes.MARKER,{color:poicolor,text:poi_id}),
			position: latLng, 
			map: RCDMap.map,
		});

		RCDMap.markers[RCDMap.numMarkers] = marker;
		RCDMap.numMarkers++;

		google.maps.event.addListener(marker, 'mouseover', function(e) { 
			RCDMap.currentUrl = url; 
			RCDMap.mapNote.html("<span>" + title + "</span>").show()
				.css('top', '0px')
				.css('left', '0px')
				.css('display', 'block')
				.css('width', 'auto')
				.css('color', '#ffffff')
				.css('background', '#000000')
				.css('padding', '2px 5px 2px 5px');

			$(document).mousemove(function(e) {
				$("#map_note").css({
					'top': e.pageY-10, 	
					'left': e.pageX+15
					});
			}); 

		});

		google.maps.event.addListener(marker, 'mouseout', function(e) {
			RCDMap.mapNote.hide();
			$(document).unbind("mousemove"); 
		}); 

		google.maps.event.addListener(marker, 'click', function(e) {
			window.location.href = RCDMap.currentUrl; 
		}); 
	},
 

The goal is that every marker has its own letter (poi_id) and color (poicolor). This used to work fine, but suddenly something happened and now is every marker getting the same letter and color as the last marker.

The titles, links etc. working fine and are unique for every marker. Any suggestions about what I am missing?

You can see the problem live at: http://www.zwedenweb.com/bezienswaardigheden-en-attracties/

Thanks in advance!

/Jasper

Link to comment
Share on other sites

I'm not up-to-speed enough on Google Maps to be able to troubleshoot very well. But if it stopped working on its own without there being some change somewhere, then it's got to be related to a change at Google Maps? Still, you might want to put a console.log(poi_id) and console.log(poicolor) in there to monitor and isolate what's going on. It would be nice to know specifically where the info is getting lost. 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...