Custom google map

  • Hello,


    I would like to create my own custom google map, using a custom latitude and longitude.


    I've taken a copy of public_maps.js, and have named the copy map_custom.js, which is located in my perch/addons/plugins/maps/map_custom.js


    I've included define('PERCH_MAP_JS', 'perch/addons/plugins/maps/map_custom.js'); in my config.php file.


    I've included define('PERCH_GMAPS_API_KEY', 'my api key'); as well.


    In my map_custom.js file, where would I go about customizing the latitude and longitude?


    Additionally, I'm seeing that the map currently displayed on my page is in fact a static map , and is not a javascript map which I've enabled the api key for.


    I'll post my code too.:burd1:


    map.html

    Code
    1. <div>
    2. <perch:content id="map" type="map" label="Address" width="640" height="360" zoom="15">
    3. </div>


    map.php (the page that I would like to use to display my custom map.)

    PHP
    1. <div class="container">
    2. <?php perch_content('Map'); ?>
    3. </div>


    map_custom.js (a copy of public_map.js.)

  • drewm

    Approved the thread.
  • Hey there, thanks for your response.


    Yes, so for example the default map displays a location, London. However I would like to display my own locations(latitude and longitude) instead of London.


    I thought that the location(s) would be customizable in my map_custom.js file, which is a copy of the default perch public_maps.js.


    Any advice?

  • The idea with the map field type is that you can search for a location and plot a pin anywhere you like. Obviously the map needs to start off somewhere by default, but that should have no impact on how you're able to use the field.

  • Yes, however I would like to have multiple locations on the map, rather than one location that is added via the control panel. Additionally, I’m seeing that the map on my live page is not interactive in that I’m unable to actually click the location pen, or drag the map..is this something that I could change in my map_custom.js file? Thank you again for your response :burd1:

  • Changing the public_maps.js file won't change how the field type behaves in the control panel (that's why it's labelled as _public_). To gather multiple points for a map, you can use multiple map field types and then create a custom output for them using the Google Maps API in your own template.

  • Okay, thank you. So, I've included define('PERCH_MAP_JS', 'perch/addons/plugins/maps/map_custom.js') in my config.php, this should allow perch to use my custom "map_custom.js" file instead of the default "public_maps.js", right ?


    Also, should I be making my customizations in my custom "map_custom.js" file, as its a copy of "public_maps.js"? From what I understand, the default "public_maps.js" should not be modified, but copied, and the copy modified per this documentation https://docs.grabaperch.com/templates/field-types/map/


    Thanks again for taking the time to answer my questions. Love using Perch! I'm just stuck on this one feature.