-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map Appears to be Limiting the Number of Markers Shown #32
Comments
I've got the same problem, any solution available? |
I'm not at my computer at the moment unfortunately, but I was able to find a workaround to get the markers to populate. I will try to find the code and post it later, but basically, I added the markers (their address, location, details, etc.) to an array and then iterated through that using the GoogleMaps function that you'll find at the bottom of your page if you inspect the source. Hopefully, that makes sense. Again, I'll try to get something up later that's a bit more detailed. |
Thanks for your reaction, looking forward to see your code. Thanks! |
Hopefully, this makes some sense. Tried to take out some of the stuff and reassemble. <script type="text/javascript">
//CREATE THE ARRAY
var markerArray = [];
//LOOP OVER THE ENTRIES WHICH IN MY CASE ARE PROFILES
{% for profile in profiles %}
//SET THE MARKERS
{% if profile.residentLocation.markers is not empty %}
//SET "geoaddress" VARIABLE EQUAL TO <latitude>,<longitude> OF MARKER
{% set geoaddress = profile.residentLocation.markers[0].lat~","~profile.residentLocation.markers[0].lng %}
//I WANTED THE PHONE NUMBER IN THE CONTENT OF THE MARKER
{% if profile.phone is not empty %}
{% set slicedphone = profile.phone | slice(0, 3) ~'.'~profile.phone | slice(3, 3) ~'.'~profile.phone | slice(6, 4) %}
{% else %}
{% set slicedphone = profile.phone %}
{% endif %}
//HERE I'M CREATING AN OBJECT WITH ALL OF THE INFO I WANT IN THE MARKER
currentArray = {
title: "{{profile.title}}",
lat: "{{profile.residentLocation.markers[0].lat}}",
lng: "{{profile.residentLocation.markers[0].lng}}",
content: "{{profile.title}}<br>{{profile.residentLocation.markers[0].address}}<br>{{slicedphone}}<br><a href=\"/{{profile.uri}}\">View Profile</a><br><a href=\"http://maps.google.com/?q='{{profile.residentLocation.markers[0].address}}\" target=\"_blank\">Get Directions</a>",
customContent: true,
address: "{{geoaddress}}",
isNew: false,
deleted: false
};
//AS I FINISH THE LOOP, I ADD THE currentArray OBJECT TO THE markerArray ARRAY
markerArray.push(currentArray);
{% endif %}
{% endfor %}
//FINALLY, I USE THE COMPLETED markerArray TO POPULATE THE MARKERS INTO THE MAP WITH ID "mainMap" (YOU MAY NOT NEED THE DELAY FROM setTimeout)
$(function(){
$(window).load(function() {
setTimeout(function mapMarkerLoad() {
new GoogleMaps.MapData(mainMap, {
"markers": markerArray,
"polylines": [],
"routes": [],
"circles": [],
"groundOverlays": []
}, []);
}, 100);
})
});
</script> EDIT: Also, I probably should have clarified that this script is in a Craft Twig template file. (Hence all the braces) |
I have no idea what would cause the script to limit you to only 10 markers on the map. I will do some tests locally, but I really don't know why this would be occurring. There shouldn't be anything in the code to limit you to only 10 markers. So do you have 150 entries each with one marker? Or does each entry have multiple markers? |
every entry has one address. its an website for real estate company. |
When you view the source of the page, do you see more than 10 instances of the "new GoogleMaps.Marker(...)"? |
var map = new GoogleMaps.Map(document.getElementById("oh-map-map"), {"maxZoom":14,"api":true}); new GoogleMaps.Marker(map,{"address":"Patrijsstraat87Neede","content":"Patrijsstraat 87 Neede"}); new GoogleMaps.Marker(map,{"address":"Pastoor Scheepersstraat33Vragender","content":"Pastoor Scheepersstraat 33 Vragender"}); new GoogleMaps.Marker(map,{"address":"Kruiskamplaan138Eibergen","content":"Kruiskamplaan 138 Eibergen"}); new GoogleMaps.Marker(map,{"address":"Hoogkamp85Eibergen","content":"Hoogkamp 85 Eibergen"}); new GoogleMaps.Marker(map,{"address":"St Isidorushoeveweg23Rietmolen","content":"St Isidorushoeveweg 23 Rietmolen"}); new GoogleMaps.Marker(map,{"address":"Meidoornstraat31Eibergen","content":"Meidoornstraat 31 and many more.... |
Right, so I see the issue. The issue is Google has a limit to the number of geocoder requests you can perform consecutively, so this is the issue. For some reason, the latitude and longitude isn't being added to the marker objects, so the script has to geocode the address for each marker. I am doing some testing now, I will see if I get this issue locally. |
Thanks, keep me updated:) |
Can you post your template code? |
{% set options = { id: 'map', width: '100%', height: '900px', maxZoom: 14, } %} {{ craft.googleMaps.map(options) }} {% for entry in craft.entries.section('koopWoningen') %} {% set city = entry.plaatsnaam %} {% set street = entry.straat %} {% set housenr = entry.huisnummer %} {% set combinedata = street ~" "~ housenr ~" "~ city %} {% set marker = { address: street ~ housenr ~ city , content: combinedata, } %} {{ craft.googleMaps.marker('map', marker) }} {% endfor %} |
Ok, so you aren't using the same code as the person who opened this thread. Are you using the field type to store your locations in the db? The field type geocodes each location and stores that in the db so each marker has a valid lat/lng so you don't have to perform additional geocoding requests to plot your data. |
I use an XML to import (Feedme plugin) the houses into craft and I’m not able to put the addresses into the field group created by the plugin. So its not possible to geocode them on the server side with the plugin fields.
|
Interesting. I also had multiple instances of "new GoogleMaps.Marker(...)" on my page as well. It made sense that Google might have had a limit, but I hadn't found anything when I had done my search. I'm curious to see what you find while testing locally—though, as I said, it's currently functioning with the workaround on my site. |
@Floriswijgergangs Well this is a pretty hard requirement. Google Maps for Craft has the ability to geocode address fields to a location when an entry is saved. Go to the plugin settings and setup the geocoder for your section. If the import plugin triggers core Craft methods to save the entry, the events should be triggered properly so your entries can be geocoded automatically. Without lat/lng coordinates for each entry, you will be constantly running into this issue. Is the geocoder method doesn't work, you'll have to figure something else out. This isn't a limitation of Google Maps for Craft, but a limitation of Google Maps API itself. |
Thanks for the feedback I’m trying to use the server side geocode. Ive include an googlemap field in the section ’koopwoningen’. PHP warning Invalid argument supplied for foreach() /Users/Floris/craft-1/worm/craft/plugins/googlemaps/GoogleMapsPlugin.php(113) 101 // If no address was entered, return script with no changes to db.
|
Can you take a screenshot of how you have your settings configured? I think that error is being thrown because you haven't defined any Google Maps fields. |
In attachment print screens.
|
@DigitalHodgePodge I am testing now for multiple markers (more than 10) and it's working for me. Here is me code I am using to test currently. I am just using the
|
@Floriswijgergangs I am not seeing that screenshot. It doesn't seem to have uploaded correctly. Can you try again? |
I think there is a bug when you check the "all" option. Can you uncheck the top option and just select the "mapsaddress" field to see if that fixes that PHP error? |
Yeah workin:). Key "lat" for array with keys "0" does not exist
|
Look at the code example I posted above in reference to the other person posting in the thread. You are getting that error because |
I'm running into the same problem here even though I've entered all my locations manually and there are latitude/longitude values in the database. Looking at my source I am getting new instances of GoogleMaps.Marker for each location on the map. Should I be passing lat/long values instead of address in the marker field?
|
Use the latitude and longitude so the address doesn't have to be geocoded with every page load. Always use the lat/lng when available to display markers over using the address. The address is just convenient for very small and static datasets. |
Got it. So is there a index of the tags available? I finally got it to work with lat: markerCustom.lat and lng: markerCustom.lng, but didn't see it anywhere in the wiki. |
Yeah, I think the only place I have it spelled out to use the lat/lng in this use case is here. https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Template-Reference#marker |
I'm running into an issue when using {{ craft.googleMaps.marker('mapID', markerInfo) }} to add markers to the map. It appears I'm being limited to 10 markers; however, the loop that this is found in is returning 150 entries.
Is there a way that I can display more markers on the map? I was looking for a parameter that I might be able to set in the map's options, but I wasn't able to find anything.
The text was updated successfully, but these errors were encountered: