Jump to content

Map Marker Map


ryan

Recommended Posts

Success, adding to MarkupGoogleMap.js... (not RCDMap.js!)

        var ctaLayer = new google.maps.KmlLayer({
        url: 'http://googlemaps.github.io/js-v2-samples/ggeoxml/cta.kml',
           map: this.map
          });

at line 126...

Thanks for help!

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

The MapMarker field does not seem to work properly in the following situations:

* In a Repeater in PW 3.0 with dynamic content loading. Only way here is to disable it completely so you have to save before every new item ;(

* With FieldsetTab if the field is not on the first page of adminpage ;(

Any chance of fixing this? 

All the best, D

Link to comment
Share on other sites

The MapMarker field does not seem to work properly in the following situations:

* In a Repeater in PW 3.0 with dynamic content loading. Only way here is to disable it completely so you have to save before every new item ;(

* With FieldsetTab if the field is not on the first page of adminpage ;(

Any chance of fixing this? 

All the best, D

Take a look at this PR (https://github.com/ryancramerdesign/FieldtypeMapMarker/pull/11) - I haven't tested it, but hopefully it will take care of what you need.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

is there a possibility to have multiple marker icons?

Right now I have "locations" pages, that belong to a category. Depending on the category I want to show different marker icons.

echo $map->render($locations, 'geo', array(
    'icon' => $icon,
    'markerTitleField' => 'title',
    'useMarkerSettings' => true,
    'fitToMarkers' => true
  ));

Thanks for any help.

Link to comment
Share on other sites

  • 2 weeks later...

@pmichaelis + @chugurk

maybe my answer help both of you...

i use MapMarker Field only in backend to get lat and long data from adresses and use them with leaflet cluster maps to generate frontend output from the geodata...

in your main template or header add needed scripts:

<!-- set extra scripts to load if there was a map on the page -->
<script type="text/javascript" src="<?php echo $config->urls->templates?>theme/js/jquery.min.js" ></script>
<script src="<?php echo $config->urls->templates?>theme/js/leaflet.js"></script>
<script src="<?php echo $config->urls->templates?>theme/js/leaflet.markercluster.js"></script>
<link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/leaflet.css">
<link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/MarkerCluster.css">
<link rel="stylesheet" href="<?php echo $config->urls->templates?>theme/css/MarkerCluster.Default.css">

in your template to show the map with many markers using marker cluster output you could use something like this:

//set output
$map = '';
$addressPoints = '';

//get all addresspoints for the JS of the MarkerCluster
$items = $pages->find("template=entry, map!=''");
foreach ($items as $m) {
	if  ($m === $items->last()) {
		$addressPoints .= '['.$m->map->lat.', '.$m->map->lng.', "<a title=\"'.$m->title.'\" href=\"'.$m->url.'\">read more</a>"]';
	} else {
		$addressPoints .= '['.$m->map->lat.', '.$m->map->lng.', "<a title=\"'.$m->title.'\" href=\"'.$m->url.'\">read more</a>"],';
	}
}

        //render cluster map with all items
	//centered to bavaria lat/long!!
	//set the needed inline JS for the map content
	$inlineJS = "
		<script>
			var addressPoints = [$addressPoints];
			var tiles = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
					maxZoom: 18,
					attribution: '© <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a>'
			}),
			latlng = L.latLng(48.1835,11.8570);

			var map = L.map('map', {center: latlng, zoom: 8, layers: [tiles]});

			var markers = L.markerClusterGroup();

			for (var i = 0; i < addressPoints.length; i++) {
				var a = addressPoints[i];
				var title = a[2];
				var marker = L.marker(new L.LatLng(a[0], a[1]), { title: title });
				marker.bindPopup(title);
				markers.addLayer(marker);
			}

			map.addLayer(markers);
		</script>
		";

	$map .= '<div id="map"></div>';
	$map .= $inlineJS;
	$content .= $map;

This should render a map like the developer locations map http://directory.processwire.com/map/ with marker clusters...

for single marker output there should be a lot of information in the topic if you search or read for it....;)

https://processwire.com/talk/topic/9711-map-marker-map/page-2#entry18338

https://processwire.com/talk/topic/9711-map-marker-map/page-2#entry21061

https://processwire.com/talk/topic/9711-map-marker-map/page-3#entry28913

since post #98 you could use MarkupGoogleMap too render a map on frontend:

https://processwire.com/talk/topic/9711-map-marker-map/page-5#entry41984

please read carefully before asking and provide code examples if you get stucked....

best regards mr-fan

  • Like 5
Link to comment
Share on other sites

  • 3 weeks later...

As per Google recent announcement, usage of the Google Maps APIs now requires a key. I've tried to use @ryan's Map Marker (Google Maps) but it errors out due to this. I would assume the module needs updating to allow for an API key field?

I believe this line, within '' needs to be changed from:

public function init() {
	$this->config->scripts->add(($this->config->https ? 'https' : 'http') . '://maps.google.com/maps/api/js?sensor=false'); 
	return parent::init();
}

to

public function init() {
    $this->config->scripts->add(($this->config->https ? 'https' : 'http') . '://maps.googleapis.com/maps/api/js?key=API_KEY_HERE&callback=initMap'); 
    return parent::init();
}
  • Like 2
Link to comment
Share on other sites

Man Google is such a nice service provider. I cannot imagine how many google maps implementations they broke just by applying policy changes "as of now". I mean I didn't like instagrams move to only "approved apps", but at least they told people about is half a year beforehand. 

  • Like 2
Link to comment
Share on other sites

8 hours ago, Robin S said:

If you mean the message in your browser console I think it's just a warning rather than an error. I'm using the Map Marker module without an API key and it's working fine.

Doesn't for me; I got two error messages (which doesn't break the map) and then a forced error which returns this:

https://www.latecnosfera.com/2016/06/google-maps-api-error-missing-keymap-error-solved.html

  • Like 1
Link to comment
Share on other sites

22 hours ago, John the Painter said:

Doesn't for me; I got two error messages (which doesn't break the map) and then a forced error which returns this:

https://www.latecnosfera.com/2016/06/google-maps-api-error-missing-keymap-error-solved.html

Thanks for the info. Seems that this affects all new map applications and existing applications (like mine) are grandfathered.

Link to comment
Share on other sites

To complicate things, there are different api keys needed for LIVE / STAGING / LOCALHOST environments?  That's how I understand the changes.

Edit:

Just learned: localhost and staging can/needs to be added at google to share one api

Link to comment
Share on other sites

  • 2 weeks later...

To supplement @John the Painter's answer:

1. Update InputfieldMapMarker.module to get your API key however you're managing it:

public function init() {
	$apikey = // get my api key
	$script_path = ($this->config->https ? 'https' : 'http') . "://maps.googleapis.com/maps/api/js?key={$apikey}";
	$this->config->scripts->add($script_path); 
	return parent::init();
}

2. Enable 'Google Maps Geocoding API' in your Google API Console for your site's API key: https://console.developers.google.com/apis/api/geocoding_backend/overview

You may need to enable whichever other individual APIs (places, geolocation, etc.) from Google's API library for the client side if you use the same API key: https://console.developers.google.com/apis/library

 

Updating the MapMarker module will remove these changes if this file is affected by the update.

  • Like 2
Link to comment
Share on other sites

On 10.07.2016 at 6:24 PM, larrybotha said:

To supplement @John the Painter's answer:

1. Update InputfieldMapMarker.module to get your API key however you're managing it:


public function init() {
	$apikey = // get my api key
	$script_path = ($this->config->https ? 'https' : 'http') . "://maps.googleapis.com/maps/api/js?key={$apikey}";
	$this->config->scripts->add($script_path); 
	return parent::init();
}

2. Enable 'Google Maps Geocoding API' in your Google API Console for your site's API key: https://console.developers.google.com/apis/api/geocoding_backend/overview

You may need to enable whichever other individual APIs (places, geolocation, etc.) from Google's API library for the client side if you use the same API key: https://console.developers.google.com/apis/library

 

Updating the MapMarker module will remove these changes if this file is affected by the update.

 

Added pull request for this issue : #14

If you want, you can apply my changes to your files or you can directly download applied version.

 

I added 2 option for FieldtypeMapMarker module settings, api key and url parameters.

FieldtypeMapMarkerSettings.jpg

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

i am using processwire v3

i installed mapmarker module. crate a map field and add it to temple.

When i try to open template from admin field map not coming. ! mark comes and says js file error.

what should i do?

some people says api key related but i dont know what to do

Link to comment
Share on other sites

hi, i tried forked version of @ukyo , i installed it and and get the apikey (browser type) for my project.

then i add api key  from module config page. now admin panel works fine with map.

i add

<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?sensor=false'></script>

to template file as told on the read me file.

When i try to load the template it said "opps ! something went wrong"

so i added

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key=API_KEY&sensor=false"></script>

now it works fine.

Is it bad for me to use this with api key on my template? because everybody can see my key by view soruce of page

 

 

Link to comment
Share on other sites

  • 5 weeks later...
29 minutes ago, bernhard said:

@Kemal you are right, you have to add the api key to the google script! you can limit requests to the google api in your google console to your domain to prevent abuse from other people.

@ukyo thanks for the fork, any news about an official pull request / merge?

@ryan updated module, now you can update module directly from admin panel

  • Like 3
Link to comment
Share on other sites

Hey folks!

I managed to get this working with multiple markers (using a repeater).
Following this thread, I even got the hoverBox with a custom field working. 

Only Problem I have now, is that I need different icons for each marker.
With my noob developer skills I can't get it to work.

Here is what I tried:

<?php
    $map = $modules->get('MarkupGoogleMap'); 
    $options = array(
    'height' => '100%',
    'width' => '100%',
    'icon' => '$page->map_repeater->marker_icon->url',
);
      $items = $page->map_repeater;
echo $map->render($items, 'map', $options); 
                 ?>

"marker_icon" is an image field in the repeater I want to use for the Icons.
Can someone please help me with this?
Thanks for this awesome module btw.!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...