Different default viewports in Google Static Streetview API vs Google Maps Embed API - google-maps

I'm looking for a way to get the default heading in the Google Maps Streetview Embed with the same accuracy/heading as the static Streetview.
For a project I'm using the Google Maps static Streetview API to create a snapshot/front facing view of an address. The way I do this is to first find the address LatLng with the Google GeoCode API, using the full address (streetname+house_number+house_number_addition+zipcode+city). With the latLng I then call the Static streetview API to fetch a snapshot of this location.
https://maps.googleapis.com/maps/api/streetview?size=900x600&location={$latLng}&key={$key}"
As you can see there is no heading param specified so the API determines the best possible heading based on the given LatLng, as specified in the API docs.
The result is spot on for 99% of the cases, in which the house is almost perfectly centered in the streetview snapshot.
The Google maps streetview embed has a very different result. The steps leading up to the creation of the embed URL are identical (find the latlng based on the full address, and use the LatLng as the location in the embedcode)
https://www.google.com/maps/embed/v1/streetview?key={$key}&location={$latLng}"
resulting in the iframe HTML
<iframe src='{https://www.google.com/maps/embed/v1/streetview?key={$key}&location={$latLng}"}' width='600' height='450' frameborder='0' style='border:0;' allowfullscreen='' aria-hidden='false' tabindex='0'></iframe>
In this case the heading or camera direction is in many (not all) cases almost facing opposite of the targeted house. Of course this can be adjusted using the heading param, but it's strange that both streetview API's differ so much in the chosen heading.

After some more digging I found the answer here. The solution is to first use the Directions API to navigate to the given location, which sets the heading facing the location. Then use the getPanoramaByLocation method of the StreetviewService to determine the correct heading.
So instead of constructing the embed code serverside, the best approach seems to create the Streetview in the frontend using the Google Maps API.

Related

Google Map static vs Dynamic business and buildings view

I have a problem when i try to display a static map that display all elements
for example:
http://maps.googleapis.com/maps/api/staticmap?&zoom=18&size=640x640&markers=color:red|40.7191413,%20-73.9973273
In it i can't view any business and buildings.
If i display same map with same zoom in google maps or in any other application that dsplay dynamic map
i can view them.
For example:
https://www.google.it/maps/place/40%C2%B043%2709.1%22N+73%C2%B059%2751.0%22W/#40.7191413,-73.9973273,18z/data=!4m2!3m1!1s0x0:0x0
I have read this faq:
https://developers.google.com/maps/documentation/business/faq#no_pois
and tryng to apply it in this mode:
http://maps.googleapis.com/maps/api/staticmap?&zoom=18&size=640x640&markers=color:red|40.7191413,%20-73.9973273&style=feature:poi.business|element:all|visibility:on
but don't work
I's a limit of Static Map o what?
The Static Map API typically shows fewer points of interest compared to Google Maps or the Maps JavaScript API. This is working as intended, so unfortunately you can't do anything to get more POIs to show up.
You can consider using the Google Maps Embed API which might better meet your needs.

how to get google maps route by sending the two latitudes and longitudes

Basically what I want is to use a webView to show google map but an URL wish I could send both the position of origin and destination so that when the page is loaded the route is displayed.
I have a list of positions of different branches and would like to do is to select a branch is displayed on the map the shortest route from the position where the device is located and the selected branch.
There is an option that is the Google Maps URL Scheme, but not how it works.
https://developers.google.com/maps/documentation/ios/urlscheme
You have to use Google Directions API to calculate the route. If you are showing the map using Google Maps JavaScript API you can use Direction Service that is included in the Map itself.
I found a solution that turned me perfect for what I needed and use a webView and link to google maps route with two positions as follows:
https://www.google.cl/maps/?saddr=origin_latitude,origin_longitude&daddr=destination_latitude,destination_longitude&directionsmode=transit

Place markers through search in Google maps API (static)

I am currently working with the Google Maps API and returning static maps (images) from the API.
I need to place markers on the map. The documentation says how to place markers on the map by defining long/lat values: http://code.google.com/apis/maps/documentation/staticmaps/#Markers
My problem is that i donĀ“t know where to place the markers. I want a google maps search phrase to determine the placement of the markers. Is that possible?
To sum up:
I want to submit a search phrase to the API and have a static map (image) returned with markers matching my search phrase.
You can place markers based on an address:
http://maps.google.com/maps/api/staticmap?center=55.665149742004,12.5627200816055&zoom=12&size=640x640&sensor=false&maptype=hybrid&markers=color:blue|label:S|smallegade%201,%20frederiksberg
Yes, it's possible. Try this:
http://code.google.com/intl/pl/apis/maps/documentation/geocoding/
This particular link regards to Maps API Web Services, but there are others api, for javascript for instance.
Generaly you need Geocoging that tranlate address to latitude and longitude
I believe you can not search a term in Maps Static version. It is not in the accepted parameters: https://developers.google.com/maps/documentation/maps-static/dev-guide#Usage
Try using Embed or JavaScript versions instead.

google maps: use directly on google server?

Usually u have to set up a little script + htmlpage on your server to run google maps,
but i was wondering - is it possible to use google maps directly?
i mean by just calling an url with parameters (gpoint coordinates, zoomfactor ..) and it loads the map fullscreen without having to use my own server?
Sounds like you might be after the static maps api. You can build a URL specifying the properties of the map like:
zoom
position
markers (including custom markers)
image size
etc
and you will get back a rendered image of the map. Something like:
Obviously this just gives you a fixed image of the map you are after. If you need a dynamic Google map, then you will need to use the Google Maps Javascript API.
Not hosted by Google. You might find some other website that uses the API to do the same thing.
Google Maps API

Can I change the marker in a Google Maps embedded map (iframe)?

I know I can do it with the Google Maps API, but do you know if there is a way to change the marker in an embedded Google Map?
I want to replace the default "A" button for a "B" button or the marker with just a dot in the middle.
I haven't played around with embedding Google Maps before (I generally go straight to the API for stuff like this). I tried a couple of approaches:
I figured maybe the embed syntax would be the same as the static maps api. So I grabbed a static maps URL, copied the markers param from that and tried sticking it into the iFrame URL. This didn't work so much.
I created a Google MyPlaces and customized the marker to use the one your provided. This created a Test map which had the appropriate marker icon. I then grabbed the embed code and stuck it on a test page and voila!
Actually I had the same problem but didn't use any of the methods above and thought I share:
If you only want a marker as I did but don't want to use API then simply fool google into thinking you want a route planned using the GET tags "saddr" and "daddr"
"saddr" defines your start location (post code , street name+ number, whatever)
ONLY define saddr and leave out daddr and google maps will by default still show the marker for "A" (your start location) exactly where you want it , all in iframe without API.