Importing Polylines: template?

New home Forums Pro Add-on General queries Importing Polylines: template?

  • This topic has 13 replies, 3 voices, and was last updated 5 months ago by Matthew.
Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #72784
    frasermarlow
    Participant

    I am struggling to get the right format passed to the importer for polylines. Could you please provide a similar file as https://www.wpgmaps.com/wp-content/uploads/Example.csv (which covers markers), but one that covers Polylines?

    I am importing from a Google Sheet, which also messes with the escape characters, but I am checking the ‘Advanced Options’ > ‘Schedule’ > ‘View Response’ to check the format of the incoming data.

    Thanks.

    #72785
    frasermarlow
    Participant

    PS: If it helps here is the Google Sheet I am using where I lined up the data for import:
    https://docs.google.com/spreadsheets/d/1VUkdPKIbEXeFacr7hLX1negnYFqSLr_gKFgicxyolAc/edit#gid=0

    #72786
    frasermarlow
    Participant

    Also, the data structure I followed was taken from the .json export file:

    “polylines”: [
    {
    “id”: “2”,
    “map_id”: “2”,
    “polydata”: “[{\”lat\”:\”39.97165787799915\”,\”lng\”:\”-75.1809790956863\”},{\”lat\”:\”39.97280969588638\”,\”lng\”:\”-75.18074342123326\”}]”,
    “linecolor”: “#fbff00”,
    “linethickness”: “12”,
    “opacity”: “1”,
    “polyname”: “800 N 27th block from Parish to Poplar”
    }]

    • This reply was modified 5 months, 2 weeks ago by frasermarlow.
    #72788
    frasermarlow
    Participant

    When I run the importer against this sheet WP Google Maps confirms:
    “CSV Data
    Polyline data found.”
    but the polylines are not added to the database.

    For example, the following is valid JSON:

    [{“lat”:”39.961956435929324″,”lng”:”-75.15926004060516″},{“lat”:”39.96121970249483″,”lng”:”-75.14669501148711″}]

    but if I add this to the Google Sheet and run the scheduled import, WP Google Map shows the following (with doubled doublequotes)

    “id”,”map_id”,”polydata”,”linecolor”,”linethickness”,”opacity”,”polyname”
    “200”,”4″,”[{“”lat””: “”39.97165787799915″”,””lng””: “”-75.1809790956863″”}, {“”lat””: “”39.97280969588638″”,””lng””: “”-75.18074342123326″”}]”,”#fbff00″,”12″,”1″,”MyName1″
    “201”,”4″,”[{“”lat””:””39.961956435929324″”,””lng””:””-75.15926004060516″”},{“”lat””:””39.96121970249483″”,””lng””:””-75.14669501148711″”}]”,”#ff9500″,”12″,”1″,”MyName2″

    If I try to escape the double quotes in the Google doc as follows:

    [{\”lat\”: \”39.97165787799915\”,\”lng\”: \”-75.1809790956863\”}, {\”lat\”: \”39.97280969588638\”,\”lng\”: \”-75.18074342123326\”}]
    [{\”lat\”:\”39.961956435929324\”,\”lng\”:\”-75.15926004060516\”},{\”lat\”:\”39.96121970249483\”,\”lng\”:\”-75.14669501148711\”}]

    Then the response looks like this:

    “id”,”map_id”,”polydata”,”linecolor”,”linethickness”,”opacity”,”polyname”
    “200”,”4″,”[{\””lat\””: \””39.97165787799915\””,\””lng\””: \””-75.1809790956863\””}, {\””lat\””: \””39.97280969588638\””,\””lng\””: \””-75.18074342123326\””}]”,”#fbff00″,”12″,”1″,”MyName1″
    “201”,”4″,”[{\””lat\””:\””39.961956435929324\””,\””lng\””:\””-75.15926004060516\””},{\””lat\””:\””39.96121970249483\””,\””lng\””:\””-75.14669501148711\””}]”,”#ff9500″,”12″,”1″,”MyName2″

    #72789
    frasermarlow
    Participant

    I am running
    WP Google Maps Version 8.1.22
    WP Google Maps – Pro Add-on Version 8.1.20

    #72790
    frasermarlow
    Participant

    Final comment… I would assume the import data structure would match that seen in the json export, specifically that the lat and long values are passed as strings, not floats. This said, in the interface (when adding a polyline manually) these values are treated as floats like this:

    [{“lat”:39.96622959631999,”lng”:-75.15685313168349},{“lat”:39.96471657912148,”lng”:-75.15187495175185}]

    and I have tried this also in the google sheet, but so far not success because the double quotes around the keys (“lat” and “lng”) still get messed up.

    #72794
    Matthew
    Moderator

    Hi there,

    Thank you for getting in touch with us, we do appreciate your time.

    As you are wanting to import polylines, we would recommend using a JSON file for this. You may then upload this JSON on your server via FTP, and then use the URL of the file in the URL field when setting up a scheduled import.

    I have created a simple JSON file for you here which showcases how the JSON polyline import file should look, thus you may have a look at it here: https://drive.google.com/file/d/1MYAEM6vAm8A6r-wEMhd6OUOOuw2o9hiq/view?usp=sharing

    Thus please may I ask if you may create a JSON file using this template and then enter your polyline data in the same structure seen in the example above. You may keep all the example data in the JSON file above, thus you may just replace the polyline data.

    Once this has been done, please may you import the JSON file and confirm if this helps?

    Kindest Regards,
    Matthew

    #72813
    frasermarlow
    Participant

    Thanks Matthew.
    After some trials I was able to import using .json and the template you provided.
    Obviously it’s a shame we can’t use the same import process as for the markers using Google Sheet, as this is an additional manual integration we will need to figure out. But thanks for letting me know that this is the approach to use.
    I do note however that during the import the Polylines will be assigned new IDs (as seen in the “Edit existing Polylines” section) which are different from the IDs assigned in the .json file. And yet, the system still knows to update an existing polyline rather than add a new one when there is a change to the .json file… So I am curious how the plugin is mapping those fields, for future reference.
    Thanks.
    F

    #72816
    Matthew
    Moderator

    Hi again,

    Thank you for your response and on this.

    We are moving more towards using JSON files as this is the better way to do it, thus we would only suggest using the CSV file method for marker importer, however, this can also be done using a JSON file.

    With regards to the polyline IDs, yes each polyline that is imported may not have the same ID as assigned in the JSON file as the “ID” is used as the primary key in the polyline database table thus the “ID” will increment by 1 based on the last “ID” that was inserted into the database table as it does not allow duplicate IDs as it is a primary key.

    Lastly regarding the import updating existing polylines, this is very interesting as we currently do not support updating of existing polylines, thus I am not sure how it is updating the existing polylines. Please may you confirm if you are using the “Replace map data” import option?

    Kindest Regards,
    Matthew

    #72857
    frasermarlow
    Participant

    Hi.
    Closing the loop on this item. I have reworked our process to not rely on Google sheets and essentially reload the entire map data from .json using a plugin we wrote that calls the source data api.

    Yes, you are correct, the polylines and markers create a new ID in the database on each import in tables such as wp_wpgmza_polylines. So it’s important to select the ‘replace map data’ option in the import, otherwise the map ends up accumulating overlaping markers.

    I also notice that the .json import ignores the top level ‘Map Settings’ , namely Map Name, zoom level, width and height.

    Finally, for what it’s worth, I thought I read in the documentation that the import file had to be on an https:// connection, but our staging server is simple http:// and the importer grabs the file from there just fine.

    Thanks.

    #72864
    Matthew
    Moderator

    Hi there,

    Thank you for your response regarding this, it is much appreciated.

    That is great news that you have managed to rework your process for the import, and I am glad that it is working now.

    With regards to the JSON import ignoring the top level “Map Settings” in the JSON file, this is because when you enable the “Apply import data to” import option, it ignores the map data and simply focuses and imports the feature data such as markers or shapes. However, if you had to not enable the “Apply import data to” option, it would create a new import map with those respective settings as well as include the respective markers and shapes in that newly created/imported map.

    Lastly regarding the importing from an “http://” connection, I am not too sure where you had read this as our import documentation (https://www.wpgmaps.com/documentation/exporting-and-importing-your-markers/) only mentions:

    From here you can pick a source to import from. You can import from a remote URL, or you can upload a file to import. Click the Import button once you have selected a source.
    
    Our remote URL import supports importing Google Spreadsheets, please see our example CSV file for the format your sheet must match to be successfully imported.

    However nonetheless, it is great that you are able to import from your respective URL that you are using.

    Kindest Regards,
    Matthew

    #72897
    frasermarlow
    Participant

    Thanks. That all makes sense.
    For any other users looking to set up an API call that is scheduled within WordPress, here is the plugin I developed – I hope it can help others:
    https://github.com/frasermarlow/WP_google_map_api_caller_plugin

    Attachments:
    You must be logged in to view attached files.
    #72918
    Matthew
    Moderator

    Hi again,

    Thank you so much for your response and time on this.

    Thank you for the confirmation and for your sharing of this, we really appreciate it!

    If you ever get a chance, please may you kindly consider reviewing our plugin at https://wordpress.org/support/plugin/wp-google-maps/reviews/#new-post?

    It would really mean the world to me! And if possible, please could I kindly ask you to mention both your name and mine in the review for administrative purposes as this would be a tremendous help?

    Should you ever require any further assistance, I am more than happy to help.

    Have a fantastic day further!

    Kindest Regards,
    Matthew

    #72934
    bekway
    Participant

    Hi,
    I’m using WP Google Maps pro with Gold add on, latest versions.
    I’m having difficulty importing exported .json and .csv files into Google My Maps. I ONLY want to export and import polylines and the json file is almost identical to the sample provided by Matthew hereabove file attached). Google seems to have problems reading the data under “polydata” and give an alert saying “we can’t localise any addresses, are you sure you’ve selected the correct column?”
    I’ve also tried exporting to .kml and other formats, same thing.
    You can see the text page here: https://tourismecoteaux65.fr/cyclotourisme/

    Attachments:
    You must be logged in to view attached files.
    #72956
    Matthew
    Moderator

    Hi there,

    Thank you for reaching out to us on the Forums, we do appreciate your time.

    The issue you are experiencing is most likely due to Google My Maps not accepting JSON files as they mention that their supported import file types are “csv, tsv, kml, kmz, gpx, png, jpg, jpeg, jpe, bmp, gif, heif, heic, ods, xls, xlt, xlsx”.

    With that said, here is an example of the format used in a KML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
        <Placemark>
            <name>Test Polyline</name>
            <description>Polyline description</description>
            <LineString>
                <extrude>1</extrude>
                <altitudeMode>absolute</altitudeMode>
                <coordinates>
                    -112.2550785337791,36.07954952145647,2357
                    -112.2549277039738,36.08117083492122,2357
                    -112.2552505069063,36.08260761307279,2357
                    -112.2564540158376,36.08395660588506,2357
                    -112.2580238976449,36.08511401044813,2357
                    -112.2595218489022,36.08584355239394,2357
                    -112.2608216347552,36.08612634548589,2357
                    -112.262073428656,36.08626019085147,2357
                    -112.2633204928495,36.08621519860091,2357
                    -112.2644963846444,36.08627897945274,2357
                    -112.2656969554589,36.08649599090644,2357 
                </coordinates>
            </LineString>
        </Placemark>
    </kml>

    With that said, please may you adjust your JSON data to follow the same format shown above and save the file as a KML file (.kml) and confirm if this helps with the import into Google My Maps?

    I look forward to hearing back from you.

    Kindest Regards,
    Matthew

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.