Tuesday, March 12, 2013

Displaying the Location through GoogleMap APIs in VF Page using Webservices


Visualforce Page:

<apex:page controller="googlemapscls" >
<apex:Form >
    <apex:CommandButton value="Location" action="{!getlocation}"/>
</apex:Form>
</apex:page>

Apex Class:

global class googlemapscls{

    webservice static void getLocation(){
        String address='Ameerpet, Hyderabad';
        HTTPRequest req= new HTTPRequest();
        req.setEndpoint('http://maps.googleapis.com/maps/api/geocode/xml?address='+address+'&sensor=false');
        req.setMethod('GET');
        HTTP http =new HTTP();
        httpResponse res= http.send(req);
        System.debug('----------->'+res);
        System.debug('----------->'+res.getbody());
                                                     }
                                            }

Note:add the link to remote site settings ex: http://maps.googleapis.com

No comments:

Post a Comment