We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45674
    • 13 Posts
    I am trying to implement the GMaps 1.0.3 pl (http://www.revo.wangba.fr/gmaps-presentation.html) in my ModX CMS, since all other Google Maps packages satisfying my needs were using the old API and/or they would not work for me. I am trying to output a map of a given location with a marker at that given location. Namely, I have a resource with the following content:

    [[!Gmaps? &language=`de` &mapType=`HYBRID` &zoom=`16` &markers=`[[*id]]` &mkrLatLngTv=`[[!GeoLatLng? &address=`Street, City, Country`]]` &mapLatLng=`[[!GeoLatLng? &address=`Street, City, Country`]]`]]


    Of course, instead of "Street, City, Country" I am using a real address. In order to get the latitude and longitude of a given address in that format, I am using the following snippet called GeoLatLng:

    <?php
    $address = str_replace (" ", "+", urlencode($address));
       $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=false";
     
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $details_url);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       $response = json_decode(curl_exec($ch), true);
     
       // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
       if ($response['status'] != 'OK') {
        return null;
       }
    
       $geometry = $response['results'][0]['geometry'];
       return $geometry['location']['lat'].','.$geometry['location']['lng'];
    ?>


    Firstly, I tried just returning the latitude and longitude of my given location and it gave me the correct two numbers. I then added the &mapLatLng parameter in the snippet-call which correctly showed a map centered around my given address. Now I want to add a marker at that place but it doesn't work. I just want a marker without any fancy extras such as an info box, and I tried it by using the necessary parameters given in this example: http://www.revo.wangba.fr/one-marker-one-map.html

    However, no matter what parameters I use and how I specify them, it seems there just won't be any marker showing up. Am I doing something completely wrong?
      • 50574
      • 70 Posts
      I know this is an old thread but I've just started using Gmaps as well and I found the same problem but have figured it out from the PDF instructions, and just in case anyone else needs to know here's how to do it.

      1. Create a TV called "mkrLatLng" with a 'text' input and give it template access to the page where your map will be.
      2. Go to that page and enter your Lat & Long co-ordinates as a comma-separated list (e.g. 53.186431,-2.880361) and save the resource.
      3. The snippet to call the map should be something like
      [[!Gmaps? &zoom=`16` &mapHeight=`400px` &markers=`5` &scalable=`yes`]]
      where &markers tells it which resource ID to pull the mkrLatLng TV results from.

      This then gives great scope for being able to add multiple markers to a map using lat/long data from different resources (e.g. different store pages/locations).

      Hope this helps