@@ -51,7 +51,7 @@ class StaticMap
5151 this . mapType = options . mapType ;
5252 this . mapID = options . mapID ;
5353 this . query = options . query ;
54- this . url = this . generateMapUrl ( ) ;
54+ this . url = this . getPublicSearchURL ( ) ;
5555 this . file = new ImageFile ( cache , this . getImageJSON ( ) ) ;
5656 }
5757
@@ -89,9 +89,13 @@ class StaticMap
8989 return arr ? ! arr . length : true ;
9090 }
9191
92+ private isCords ( ) : boolean {
93+ return ! this . query && RegExp ( / ^ [ ^ a - z A - Z ] + $ / ) . test ( this . center ) ;
94+ }
95+
9296 private getImageJSON ( ) : ImageFileOptions {
9397 return {
94- baseUrl : this . url ,
98+ baseUrl : this . generateMapUrl ( ) ,
9599 clientID : this . clientID ?? "" ,
96100 format : this . format ,
97101 hasSecret : this . hasSecret ?? false ,
@@ -120,11 +124,17 @@ class StaticMap
120124 private generateMapUrl ( ) : string {
121125 return `https://www.google.com/maps/api/staticmap?${
122126 this . isImplicit ( ) ? this . parseWayPoints ( ) : ""
123- } ${
124- this . center || this . query
125- ? `center=${ encodeURIComponent ( this . center ?? this . query ) } `
126- : ""
127- } `;
127+ } ${ this . center ? `center=${ encodeURIComponent ( this . center ) } ` : "" } `;
128+ }
129+
130+ private getPublicSearchURL ( ) : string {
131+ const URLBuilder : [ dir : string , action : string ] = this . isImplicit ( )
132+ ? [ "dir/" , this . parseWayPoints ( ) ]
133+ : this . isCords ( )
134+ ? [ "@" , `map_action=map¢er=${ encodeURIComponent ( this . center ) } ` ]
135+ : [ "search/" , encodeURIComponent ( this . query ?? this . center ) ] ;
136+
137+ return `https://www.google.com/maps/${ URLBuilder [ 0 ] } ?api=1&${ URLBuilder [ 1 ] } ` ;
128138 }
129139
130140 private parseWayPoints ( ) : string {
0 commit comments