Google map with postal code and custom marker image - javascript

I'm currently using the Google Map's staticmap with a postal code and the standard red marker. I would like to use a custom png image instead of the red marker.
I've tried adding the url of the image with the marker parameter in the url but it gives an error in the map.
<img src="https://maps.googleapis.com/maps/api/staticmap?center=v302t8&zoom=9&size=460x150&maptype=roadmap&key=APIKEY&markers=color:red%7Cv302t8" alt="">
I'd like to be able to use this method as opposed to the geocoding method as they the number of queries is limited.

I don't know what the center location v302t8 ( source of the error? ) is or the final %7Cv302t8 in the map url so I modified the above as you can see below. The map loads OK and displays a custom marker image centred upon the "Tower of London"
The chosen image should be 64px x 64px or less.
https://maps.googleapis.com/maps/api/staticmap?center=51.507336, -0.074968&zoom=15&size=512x512&maptype=roadmap&key=<APIKEY>&markers=icon:http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/af/afeef641914e77b0950eb8b8317bfbf080b69ace_medium.jpg|51.507336, -0.074968
Update:
Using a png file also works - again bearing in mind the max dimensions of the marker image
https://maps.googleapis.com/maps/api/staticmap?center=51.507336, -0.074968&zoom=15&size=512x512&maptype=roadmap&key=<APIKEY>&markers=icon:https://cartoon.aminoapps.com/static/bower/emojify.js/images/emoji/skull.png|51.507336, -0.074968

Related

How to add custom marker in ar.js?

I am trying to change default hiro marker with my own marker. its black and white image in jpg format.
i generated pattern file using https://jeromeetienne.github.io/AR.js/three.js/examples/marker-training/examples/generator.html
this is code for marker
<a-marker
preset="pattern"
type="pattern"
url="https://cdn.glitch.global/8e98caee-09a2-4050-aa4b-53ddcebc0457/pattern-marker_uni.patt?v=1651161066156"
></a-marker>
you can check my code here https://glitch.com/edit/#!/oceanic-confirmed-allspice
What ever I tried , it is not triggering on this pattern. should I use nft image tracking vs marker tracking.

Problem of tiling with GeoWebCache: most tiles are missing

I set up a PostGIS database that I added in GeoServer via a parameterized SQL view. I used Leaflet to display this layer via wms.
It worked fine until I add GeoWebCache using the url "/geoserver/gwc/service/wms" instead of "/geoserver/wms". I can still see my polygons when I'm at the minimal zoom. But then when I zoom I see only a red polygon and a half of a green polygon and if I zoom again I see only the red polygon. You can see these 3 states on the images below:
I guess this is a problem of tiling: I get the minimal tiles and also some tiles around the red polygon for further zooms but for some reason it seems that the other tiles are not sent.
Here is the code I use to get my wms layer with leaflet:
geoJSONlayer = L.tileLayer.wms("/geoserver/gwc/service/wms", {
layers: 'cartowiki:choix',
format: 'image/png',
transparent: true,
viewparams: 'year:'+(annee+3000)
}).addTo(map);
geoJSONlayer.addTo(map);
Do you have an idea of the problem here ?
Thanks in advance,
The bounding box was the problem indeed. In Geoserver, I had to modify the properties of the layer in 2 places :
I clicked 'Compute from SRS bounds' and then 'Compute from native bounds' in the Bounding Boxes part of the Data section
I erased and created again the available gridsets in the Tile Caching section so that the grid subset bounds would update with the new Bounding Boxes
I hope it can help someone in the future!

Google Streetview API Indoor panorama.setPosition() redirects to start position

I am working on a Google Streetview indoor application using the Google Maps JS API. I am using panorama pictures that are available on Google Streetview. I sometimes want to programatically change the position, for instance when somebody clicks on a position in a small map. However, when I call panorama.getPosition() I automatically get redirected to a different position. I can actually see the position_changed event being triggered twice.
I already sort of found the cause of this issue. It has something to do with the starting/entrance positions Google maps uses for Streetview Indoor.
The two orange circles depict the two possible starting/entrance points into the building. When dropping the pegman over these circles you will enter the building in Streetview Indoor.
It looks like when these starting points exist, the Google Maps API does not let you programatically set the position to some position other then any of the starting points. It will always redirect you to one of the starting points. This is obviously not what I want.
//The starting/entrance position is lat: 52.089988, lng: 5.178041
//The position I want to go to
var goToPosition = {lat: 52.0898852, lng: 5.1780344};
//Position changed EventListener
google.maps.event.addListener(panorama, 'position_changed', function() {
var newPosition = panorama.getPosition();
console.log('changed position to:', newPosition.lat(), newPosition.lng());
});
//Calling setPosition with goToPosition
panorama.setPosition(goToPosition);
//Will result in two console.logs directly printed after another:
changed position to: 52.0898852 5.1780344 //goToPosition
changed position to: 52.089988 5.178041 //starting position
The console.logs show that it looks like the position is being changed twice directly after each other, ending the position at the starting position.
I'm wondering if any body else has encountered this problem and if there is a known workaround for this. I am in contact with the photographer that uploaded the panorama pictures to Google. Maybe there's something in the way these pictures are uploaded to Google and configured. I wonder if this can even be fixed in my application code, or if it's an API problem or even expected behavior.
Thanks!
I found the solution for my problem, partly thanks to #LilDevil's answer.
Each panorama for a position has a panorama ID. If you know the panorama ID in advance, it can be used to move to that position using setPano().
I store panorama ID together with the lat,lng of a position. When clicking on the map I calculate the known position that is nearest to the clicked position. I can then look up the panorama ID that belongs to this position and use it to move to that panorama using setPano().
This doesn't seem to be a very clean way to solve the problem, because the panorama ID might change over time (for instance when new panorama pictures are uploaded to Google Streetview). However, I couldn't find anything in the documentation that says this method shouldn't be used. The documentation says that this method should be used when dealing with custom panorama pictures, which is not the case in my situation. Also, in this specific situation we are in control of when new panorama pictures will be uploaded (because it's for Google Indoor) so I can change the stored panorama ID's if that happens.
You can't just set the panorama to any coords. You need to use getPanorama() with your start coords and a radius, to find the coords to the nearest panorama, then set the pano to those coords. Some examples on https://developers.google.com/maps/documentation/javascript/streetview?hl=en

AngularJS - plotting points on a map

I am new to AngularJS and I am looking to add some plotting functionality to my web app.
I have a map of the world (a png file) and X/Y coordinates that I want to overlay on top of the map image. For example, my data might look like:
[
{
'location_x':'123',
'location_y':'224',
'date':'20100505',
'text':'I loved this place!'
},
{
'location_x':'222',
'location_y':'333',
'date':'20110606',
'text':'Never again!'
}
]
I would like the date values to appear in the area designated by the x/y coordinates, and the text to appear as a tooltip for the date.
I do not need the application to expose the capability to edit the x/y coordinates, I only need to display the values that my data source gives me. I need to use a custom image as the map. What are my options for getting this done?
You could use LeafletJS .
Another option is to use the Google Static Maps API.

How to add custom street names on Google Maps?

So you want to add custom street names or other labels on your Google Map? For example on this location. After learning current (3.6) google map js API you have these possible options:
KmlLayer (not works now)
GroundOverlay (works!)
OverlayView (should work)
KmlLayer "...adds geographic markup to the map from a KML, KMZ or GeoRSS file that is hosted on a publicly accessible web server...”. We can try this latest feature to add path with label. And it will work in Google Earth. But if path is too short – Google Earth will not show us a label. Workaround for short path is just make it long by adding start and end points few times:
<coordinates>
55.043196,82.907145 55.043473,82.909902
55.043196,82.907145 55.043473,82.909902
55.043196,82.907145 55.043473,82.909902
55.043196,82.907145 55.043473,82.909902
</coordinates>
Then we already see our nice custom label in Google Earth, but in Google Map not. Most possible reason is that google earth's latest feature is too latest. Currently it’s a fail way, but may be later, google map's KML renderer will take that feature into account.
GroundOverlay is "... a rectangular image overlay on the map ...". All is much simple.
Create image:
Open your Google Earth (make sure your latitude/longitude settings are Mercator) and go to your location
Add one pixel white image on your area and make it 33% transparent
Go to properties / place tab of your image overlay and copy latitudes/longitudes from there
Make screenshot in Google Earth and paste it to your favorite graphic editor
Crop image to the borders of your white transparent area
Add layer, where you will add your custom labels and add them
Switch off your base layer and save the result as png, for example overlay.png
Add the resulting image to your google map as:
google.maps.event.addDomListener(window, 'load', function() {
var mapDiv = document.getElementById('map'),
opts = {mapTypeId: google.maps.MapTypeId.HYBRID},
map = new google.maps.Map(mapDiv, opts),
area = new google.maps.LatLngBounds(
new google.maps.LatLng(55.042297, 82.906337),
new google.maps.LatLng(55.043862, 82.910473)
),
overlay = new google.maps.GroundOverlay(
'overlay.png', area, {map: map, clickable: false}
);
map.fitBounds(area);
});
OverlayView you can try by yourself.
ps: Is this a correct format for article? Or may be it should be a community wiki?
I created a MapLabel utility library a while ago. While it doesn't have any rotation or text-on-path capabilities (I'd love to see you add it!), it does let you put text on a map.

Categories

Resources