Synchronize your contacts with Google contacts on your iPhone 3G
Basically you have two major tasks to get this done:
Task 1. Upload contacts to Google contacts from iPhone
Google Sync uses the Microsoft® Exchange ActiveSync® protocol.
When setting up a new Exchange ActiveSync account on your iPhone, all existing Contacts and Calendar events will be removed from your phone.
Please make sure to back up any important data before you set up Google Sync.
It is suggested to upload your existing iPhone contacts to Google first.
Check this for step by step guide.
Task 2. Setup Google sync on your iPhone