The country's congress on Thursday approved the proposal which will give Spain's government control over the diffusion of images of official buildings.
The law would affect sites like Google Maps, but also the Apple and Yahoo! mapping equivalents, reported El Mundo on Friday.
The move was put forward by the ruling Popular Party (PP) with the support of the Defence Commission.
"The cartographic information about sensitive installation and locations available on the internet could make it easier to put national security at risk," said the PP when it gives its reasons.
The party also said "some terrorist groups had publicly recognized the use of such tools in the planning of attacks, demonstrating the improper use of the technology".
The proposal received almost universal approval, with only the left-wing IU grouping abstaining.
No mention of any particular company was made in Thursday's motion in parliament.
Currently there are no limits in Spain on the diffusion of satellite images of national territory, reported El Mundo.
Buildings that can be viewed in detail on sites like Google Maps include the Prime Minister's residence of La Moncloa and the King's residence of La Zarzuela.
Even the National Centre for Intelligence and the other military installations can be viewed using online mapping sites.
The Spanish government's move to ban the publishing on the internet of such 'sensitive' official locations comes in the wake of a bombing during the Boston marathon which left three people dead and over 100 people injured.