Warning: These instructions are only for Mac users that sync to Address Book. I don't know the dynamics if you're syncing your contacts with Exchange, or otherwise syncing on a PC.
Once you set this up, when you're in Gmail and go to address any email Gmail will include all of your iPhone contacts in the list of contacts that it searches to auto-fill any of the address-to fields. Also you'll be able to search your contact database no matter where you are using Gmail's flexible contact search. This is nice given that iPhone doesn't yet have a contact search feature.
You sync iPhone contacts with Gmail contacts by telling Address Book to sync with Google Contacts, the ones used in Gmail. There are actually three stores to sync up:
2. Address Book (Mac)
3. Google/Gmail Contacts
The sync between iPhone and Address Book is already solid and automatic. The rest of this post is all about the sync between Address Book and Google Contacts.
First I want to say that I did have problems when I first sync'd. The problems were between contacts that I already had in Gmail that also related to contacts I had in iPhone. I got duplicate entries. It was problematic to get those cleaned up so I ended up simply deleting all my Gmail contacts, cleaning up everything on iPhone, then syncing. All was well after that.
Once sync'd up my tests showed that when you add, delete, or edit a contact on any of the three stores the changes are indeed reflected on the other two.
So here are the steps I recommend:
1. Delete all of your Gmail contacts by going to Gmail, going to Contacts, selecting "All", and then clicking on "Delete contact" button.
2. Now in Gmail click on "My Contacts" and uncheck the checkbox that says, "Automatically move suggested contacts into My Contacts if I frequently email them." This should avoid unwanted and sometimes duplicate, contact entries on your iPhone. It also forces you to explicitly add new contacts.
3. Now's a good time to optionally clean up your contact list on your iPhone.
4. Now go to Mac Address Book and tell it to sync with Gmail. On your Mac open Address Book, go to Preferences, check "Synchronize With Google", click on the button right there that says "Google...", and enter your Google username and password.
5. Sync your iPhone using iTunes.
Wahlah. You should now see all your contacts under "Contacts" in Gmail. From now on all three stores should automatically keep up with any change to your contact list no matter whether the change is originated on your iPhone, in Address Book, or in Gmail.
The sync will occur from now on every time you Sync your iPhone with iTunes.