Create URL link to Google Street View for arcgis online

2124
6
09-01-2022 11:22 AM
anonymous55
Occasional Contributor II

Hello 

I am trying to create url link using arcade for hosted layer I have.
my table just have X coordinate and Y coordinate?

anonymous_0-1662056371486.png

I looking for url like for each point to click and take them to Google street view.

0 Kudos
6 Replies
Clubdebambos
Occasional Contributor III

Hi @anonymous55 

I cannot remember where I got the full code from below but I will source and credit it once I do.

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

function AuxSphereToLatLon(x, y) {
  Console("Converting...");
  // Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
  var rMajor = 6378137;
  var shift = PI * rMajor;
  Longitude = x / shift * 180.0;
  Latitude = y / shift * 180.0;
  Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
  Console("4326 Spatial Reference - No Conversion Necessary");
  Latitude = ArcadeY;
  Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
  Console("102100 Spatial Reference - Conversion Necessary");
  AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
  Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

var url = "http://maps.google.com/maps?q=&layer=c&cbll=" + text(Latitude) + "," + text(Longitude);
return url;

 

~ learn.finaldraftmapping.com
0 Kudos
anonymous55
Occasional Contributor II

Thanks for respond I am getting this result

anonymous_0-1662059018527.png

 

0 Kudos
RhettZufelt
MVP Frequent Contributor

What do the console messages say?

R_

0 Kudos
anonymous55
Occasional Contributor II
Use Console Function to output messages.

102718 Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100
0 Kudos
RhettZufelt
MVP Frequent Contributor

It appears as if your map is in a state plane coordinate system. 
Don’t believe there is an arcade option for this unless your map is in web Mercator or WGS84. 
R_

RhettZufelt
MVP Frequent Contributor

Not sure how “dynamic” your layer is, but if possible, one option would be to add a couple columns to the feature layer with X,Y coordinates in 4326, then you could use parts of the script provided by @Clubdebambos , but just extract the xy from the WGS84 columns instead of the state plane columns.   Would also need to skip the spatial reference checks as that checks the SR of the dataset, not the values in these new columns. 
Not currently able to test this, but thought it may be an option worth  looking into. 
Of course, this requires calculating values for two more fields and might be easier to just calculate the url to a new column instead. 
R_