Git Product home page Git Product logo

Comments (29)

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

I've got the same problem, any solution available?

from google-maps-for-craft.

DigitalHodgePodge avatar DigitalHodgePodge commented on August 12, 2024

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.

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

Thanks for your reaction, looking forward to see your code. Thanks!

from google-maps-for-craft.

DigitalHodgePodge avatar DigitalHodgePodge commented on August 12, 2024

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)

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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?

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

every entry has one address. its an website for real estate company.
So every marker is an house for sale.

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

When you view the source of the page, do you see more than 10 instances of the "new GoogleMaps.Marker(...)"?

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

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....

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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.

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

Thanks, keep me updated:)

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

Can you post your template code?

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024
{% 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 %}

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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.

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

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.

Op 7 apr. 2015, om 16:57 heeft Justin Kimbrell <[email protected] mailto:[email protected]> het volgende geschreven:

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.


Reply to this email directly or view it on GitHub #32 (comment).

from google-maps-for-craft.

DigitalHodgePodge avatar DigitalHodgePodge commented on August 12, 2024

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.

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.

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

@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.

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

Thanks for the feedback I’m trying to use the server side geocode.

Ive include an googlemap field in the section ’koopwoningen’.
With the automatic geocode configured.
When I open an entry the google map field preview is displaying the correct information.
However when I save the entry. I get an php error.:

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.
102 if(!count($address))
103 {
104 return;
105 }
106
107 $response = craft()->googleMaps_geocoder->geocode($address);
108
109 if($response->status == 'OK')
110 {
111 $geocodeResponse = $response->results[0];
112
113 foreach($settings->mapFields as $mapFieldId)
114 {
115 $mapField = craft()->fields->getFieldById($mapFieldId);
116 $mapData = json_decode($content->{$mapField->handle});
117
118 $mapDataModel = new GoogleMaps_MapDataModel((array) $mapData);
119
120 // Update marker if exists, otherwise add a new marker
121 if($marker = $mapDataModel->getMarker(0))
122 {
123 $marker->lat = $geocodeResponse->geometry->location->lat;
124 $marker->lng = $geocodeResponse->geometry->location->lng;
125 $marker->address = $geocodeResponse->formatted_address;
Stack Trace
#0
– /Users/Floris/craft-1/worm/craft/plugins/googlemaps/GoogleMapsPlugin.php(113): CApplication->handleError(2, "Invalid argument supplied for foreach()", "/Users/Floris/craft-1/worm/craft/plugins/googlemaps/GoogleMapsPl...", 113, ...)
108
109 if($response->status == 'OK')
110 {
111 $geocodeResponse = $response->results[0];
112
113 foreach($settings->mapFields as $mapFieldId)
114 {
115 $mapField = craft()->fields->getFieldById($mapFieldId);
116 $mapData = json_decode($content->{$mapField->handle});
117
118 $mapDataModel = new GoogleMaps_MapDataModel((array) $mapData);
#1
unknown(0): Craft\GoogleMapsPlugin->Craft{closure}(Craft\Event)
#2

  • /Users/Floris/craft-1/worm/craft/app/framework/base/CComponent.php(567): call_user_func(Closure, Craft\Event)
    #3
    – /Users/Floris/craft-1/worm/craft/app/services/EntriesService.php(428): CComponent->raiseEvent("onSaveEntry", Craft\Event)
    423 *
    424 * @return null
    425 /
    426 public function onSaveEntry(Event $event)
    427 {
    428 $this->raiseEvent('onSaveEntry', $event);
    429 }
    430
    431 /
    *
    432 * Fires an 'onBeforeDeleteEntry' event.
    433 *
    #4
    – /Users/Floris/craft-1/worm/craft/app/services/EntriesService.php(270): Craft\EntriesService->onSaveEntry(Craft\Event)
    265 {
    266 // Fire an 'onSaveEntry' event
    267 $this->onSaveEntry(new Event($this, array(
    268 'entry' => $entry,
    269 'isNewEntry' => $isNewEntry
    270 )));
    271 }
    272
    273 return $success;
    274 }
    275
    #5
  • /Users/Floris/craft-1/worm/craft/app/controllers/EntriesController.php(451): Craft\EntriesService->saveEntry(Craft\EntryModel)
    #6
  • /Users/Floris/craft-1/worm/craft/app/framework/web/actions/CInlineAction.php(49): Craft\EntriesController->actionSaveEntry()
    #7
  • /Users/Floris/craft-1/worm/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(array("p" => "admin/entries/koopWoningen/13709-0eibergenkuipersweg"))
    #8
  • /Users/Floris/craft-1/worm/craft/app/framework/web/CController.php(286): CController->runAction(CInlineAction)
    #9
  • /Users/Floris/craft-1/worm/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array())
    #10
  • /Users/Floris/craft-1/worm/craft/app/framework/web/CWebApplication.php(282): CController->run("saveEntry")
    #11
  • /Users/Floris/craft-1/worm/craft/app/etc/web/WebApp.php(756): CWebApplication->runController("entries/saveEntry")
    #12
  • /Users/Floris/craft-1/worm/craft/app/etc/web/WebApp.php(263): Craft\WebApp->_processActionRequest()
    #13
  • /Users/Floris/craft-1/worm/craft/app/framework/base/CApplication.php(180): Craft\WebApp->processRequest()
    #14
  • /Users/Floris/craft-1/worm/craft/app/index.php(62): CApplication->run()
    #15
  • /Users/Floris/craft-1/worm/public/index.php(19): require_once("/Users/Floris/craft-1/worm/craft/app/index.php")

Op 7 apr. 2015, om 17:23 heeft Justin Kimbrell <[email protected] mailto:[email protected]> het volgende geschreven:

@Floriswijgergangs https://github.com/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.


Reply to this email directly or view it on GitHub #32 (comment).

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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.

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

In attachment print screens.

Op 7 apr. 2015, om 17:53 heeft Justin Kimbrell <[email protected] mailto:[email protected]> het volgende geschreven:

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.


Reply to this email directly or view it on GitHub #32 (comment).

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

@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 data method which will plot all the data from your field type on a map.

{% set query = craft.request.getParam('q') %}

{% set params = {
    address: query,
    distance: 200,
    unit: 'kilometers'
} %}

{% set options = {
    id: 'map', 
    width: '400px', 
    height: '300px',
    clustering: true
} %}

{{ craft.googleMaps.map(options) }}

<ul class="search-results">
{% set entries = craft.entries.section('news').map(params).order('distance asc') %}
{% for entry in entries %}
    <li>
        <h3>{{ entry.title }}</h3>

        {{ craft.googleMaps.data('map', entry.map) }}

        {% for marker in entry.map.markers() %}
            <p>Distance - {{ marker.distance }}</p>
        {% endfor %}
    </li>
{% endfor %}
</ul>

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

@Floriswijgergangs I am not seeing that screenshot. It doesn't seem to have uploaded correctly. Can you try again?

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

schermafbeelding 2015-04-07 om 17 54 35
schermafbeelding 2015-04-07 om 17 54 24

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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?

from google-maps-for-craft.

Floriswijgergangs avatar Floriswijgergangs commented on August 12, 2024

Yeah workin:).
How can I retrieve the lat en lng and translate it into one map with all markers.
{{ entry.mapsaddress.markers.lat }} does not work.

Key "lat" for array with keys "0" does not exist

Op 7 apr. 2015, om 18:00 heeft Justin Kimbrell <[email protected] mailto:[email protected]> het volgende geschreven:

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?


Reply to this email directly or view it on GitHub #32 (comment).

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

Look at the code example I posted above in reference to the other person posting in the thread. You are getting that error because entry.mapsaddress.markers returns and array of objects. Your syntax is implying that it's returning an object.

from google-maps-for-craft.

jonlongnecker avatar jonlongnecker commented on August 12, 2024

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?

{% set options = {
        id: 'map', 
    width: '100%', 
  height: '400px',
} %}

        {% set map = craft.googleMaps.map(options) %}

         {% for markerCustom in entry.blogLocations.getMarkers() %}
            {% set address = '<div class="marker-content"><h3>' ~ markerCustom.title ~ '</h3><p>' ~ markerCustom.content ~ '</p></div>' %}
            {% set marker = {
               address: markerCustom.address, 
               content: address,
            } %}
            {{ craft.googleMaps.marker('map', marker) }}
        {% endfor %}

        {{ map }}

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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.

from google-maps-for-craft.

jonlongnecker avatar jonlongnecker commented on August 12, 2024

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.

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

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

from google-maps-for-craft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.