Launch Safari browser with StreetView for a given latitude longitude

323 views Asked by At

I would like to launch Google StreetView in the Safari browser from my native iOS app. I have the street address and latitude longitude available. I know it is relatively easy to find panorama ID using an API, but unfortunately I can't use any Google API. I need to launch the google maps website outside of my app with the given address or latitude longitude.

The url for street view (for 40.535673,-74.209823) on desktop looks something like this:

https://www.google.com/maps?es_sm=91&um=1&ie=UTF-8&q=719+Ramona+ave+new+york&layer=c&z=17&iwloc=A&sll=40.535673,-74.209823&cbp=13,354.4,0,0,0&cbll=40.535462,-74.209796&sa=X&ei=BMdjVIaPMIn5yASA64Jw&ved=0CCAQxB0wAA

How can construct this url without using any Google Maps API? If I simply try to replace the latitude longitude above the street view ends up facing in the incorrect direction. Any way to get the heading just right?

1

There are 1 answers

1
Sonny Saluja On BEST ANSWER

The way I solved this was to first call the following API to get a panoId and best_view_direction_deg. Here's an example url for that API:

http://maps.google.com/cbk?output=json&ll=40.766200,-73.982500

Here's a piece of ObjC code I used to convert the pano ID and direction into a url:

+ (NSString *)bestStreetViewWebUrlForCoordinate:(CLLocationCoordinate2D)coordinate panoId:(NSString *)panoId bestViewDirectionDeg:(NSString *)bestViewDirectionDeg
{
    NSString *streetViewUrlString = nil;
    if (panoId != nil)
    {
        streetViewUrlString = [NSString stringWithFormat:@"https://maps.gstatic.com/m/streetview/?panoid=%@&cbp=0,%@,0,0,0", panoId, bestViewDirectionDeg];
    }
    else
    {
        streetViewUrlString = [NSString stringWithFormat:@"https://maps.gstatic.com/m/streetview/?q=&layer=c&cbll=%f,%f&cbp=11,0,0,0,0&output=classic&dg=brw",coordinate.latitude, coordinate.longitude];
    }
    return streetViewUrlString;
}

Output looks like:

https://maps.gstatic.com/m/streetview/?panoid=fB883QwmW5xNsXRuEHxmHw&cbp=0,207.478,0,0,0