Using a custom image marker on google static map?
Asked Answered
P

4

34

how to have custom image marker on google static map, i need url format:

this is what i have tried, but its having default marker image http://maps.google.com/maps/api/staticmap?center=25.3176452,82.97391440000001,&zoom=15&markers=25.3176452,82.97391440000001|25.3176452,82.97391440000001&path=color:0x0000FF80|weight:5|25.3176452,82.97391440000001&size=175x175&sensor=TRUE_OR_FALSE

Pilgarlic answered 13/2, 2015 at 4:52 Comment(0)
H
55

This is what you want:

http://maps.googleapis.com/maps/api/staticmap?zoom=17&size=512x512&maptype=hybrid&markers=icon:http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico|34.052230,-118.243680

for a custom image, put the icon:url after of markers...

Format

icon:url|lat,lng

Example

icon:http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico|34.052230,-118.243680

a result of my example

stackoverflow server ubication...

For more information check google maps api, there are more information like size, markers position, center map, map type... etc.

https://developers.google.com/maps/documentation/static-maps/intro#MapTypes

*If the icon, img, don't appear it will be the size of image, try with another size,less than 64x64 px, format of image, "GIF, JPEG and PNG", the documentation recommend "PNG", if it doesn't appear check permision of image for public request(external request)...

Helladic answered 19/3, 2016 at 17:31 Comment(9)
@PhilAndrews The docs says inline-defined SVG paths work, though.Imminent
is there a way to customize the height and width of that image in the url?Indoxyl
@Indoxyl yes, if you see in the url, of the api, there is an option of size=512x512 width and height, in the url of api, search for sizeHelladic
@Helladic i think thats the height and width of the image not the icon image no? I also saw that the max size is 64 * 64 on their docsIndoxyl
@Helladic Is there a way to pass icon size?Picro
Absolutely brillant.Adalbert
2018, SVG's still do not work (tested with file url, not an inline path).Defeatism
And just try to make the icon url simplified. like this siteurl/images/marker.png not like this siteurl/somedirectory/another/inner/marker.pngHoodwink
Im not seeing anywhere in the docs that you can use a custom svgpath?Melisandra
C
6

According to the documentation you can specify custom icons like so:

markers=icon:...

e.g. amending your URL:

http://maps.google.com/maps/api/staticmap?center=25.3176452,82.97391440000001,&zoom=15&markers=icon:http://www.megaadresse.com/images/icons/google-maps.png|25.3176452,82.97391440000001&path=color:0x0000FF80|weight:5|25.3176452,82.97391440000001&size=175x175

Gives you:

enter image description here

PS: the sensor parameter is no longer required.

PPS: also you seemed to have specified the same coordinates twice in your markers parameter, so it was actually drawing two markers on the same location.

Cathrin answered 13/2, 2015 at 9:9 Comment(0)
D
1

You can add an image in the marker:

var campaign_map = new google.maps.Map(document.getElementById("campaign_map_canvas"), mapOptions);


    var selected_marker = new google.maps.Marker({
        position: position,
        map: campaign_map,
        icon: 'path/to/image'
    });

google.maps.event.trigger(campaign_map,'resize');

EDIT You can use the following:

https://maps.googleapis.com/maps/api/staticmap?size=480x480&markers=icon:path/to/image.png%257C996600%7Carea/you/want/
Dianndianna answered 13/2, 2015 at 4:56 Comment(4)
That's using the JS API, not the Static Maps (the question was really mis-tagged, I've amended it)Cathrin
Google maps is mainly JS? What exactly are you looking to do then?Dianndianna
The OP is referring to this API: developers.google.com/maps/documentation/staticmapsCathrin
I resized the png icon to 64*64,, and tested this &markers=icon:path/to/image.png,,,, dunno its not working,, any idea ?? and what is this ? %257C996600%7Carea/you/want/ ??Erastatus
P
0

You must use a valid format. Taken from the official documentation:

Icon images may be in PNG, JPEG or GIF formats, though PNG is recommended

Psychopharmacology answered 21/4, 2023 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.