There are three ways a law firm can obtain favorable rankings in search engines. For organic rankings, it can become an "authority" on the topic being searched, or it can become known as the "go-to" local business for the service being searched. As an alternative to organic rankings, a firm can pay search engines to advertise alongside the search results and content it wants to be associated with.
To become an authority, a website needs a lot of unique and helpful content about the practice areas the firm wants to promote. Additionally, the more that other reputable websites link to the firm's site, the more influential the firm's site will appear to search engines. There are a bazillion technical details and strategic things to do, but basically, it comes down to:
To become the go-to local business and show up in those special page one spots labeled A-G with the map feature, search engines are looking for a number of factors regarding the law firm's location, reputation, stability, and longevity. Most importantly, the law firm has to be located in the city the person is looking in. In more populated areas, it's very hard to show up as a local business in a city where the firm does not have a physical presence. Aside from that, search engines are looking for signals that a law firm or attorney is popular and reputable. Client reviews and the frequent publication of the firm's contact information on other websites factor in here. Like the authority topic, there are tons of technical and strategic things that can be done.
Finally, a law firm can pay to advertise for the topics it wants. Depending on the practice areas, goals, and urgency, advertising may be faster, easier, cheaper, more flexible, and more predictable than all the work required to promote a website through organic rankings.
The best marketing plans often involve a strategic mix of all these approaches. Even when paying search engines to advertise, it's not enough to just throw money at them, your website, content, and advertisements all have to be great. If you have time, here is a neat video from Google's Chief Economist on how they rank advertisements.