• Douglas G
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Arcus Global

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hey all apologies, Im certain thius is something elementary but Ive been going round it for ages now and losing my tiny mind. 

Im working on a custom lightning componsnt and need to geocode adresses to put them on a map. I beleive Im correct in thinking that lightning wont let me call the geocoding WS directly from the JS and instead need to do this in apex. 

Issue Im having is I cant even get a dead simple request to googles geocode to work correctly, instead as below it returns me an error - Invalid request. Missing the 'address', 'bounds', 'components', 'latlng' or 'place_id' parameter ie not seeing the address param Im setting using req.setHeader('address', addrEncode  );. Via Postam or browser this works fine.

Apex Class
@AuraEnabled
    public static void testGeocodeWS() {
        
        System.debug('testGeocodeWS');
        String endpoint = 'https://maps.googleapis.com/maps/api/geocode/json';
        String addrRaw = 'SAPPHIRE HOUSE UNIT 2, CRISTAL BUSINESS CENTRE , 47 KNIGHTSDALE ROAD , IPSWICH , IP1 4JJ';
        String key = 'XXX OBSCURED FOR POST XXX';
        
        String addrEncode  = System.EncodingUtil.urlEncode(addrRaw, 'UTF-8' );
        
        System.debug('addrEncode = ' + addrEncode);
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(endpoint);
        req.setMethod('GET');
        req.setHeader('address', addrEncode  );
        req.setHeader('key', key );
        
        System.debug('req = ' + req);
        System.debug('req.getEndpoint() = ' + req.getEndpoint());
        System.debug('req.getHeader(\'key\') = ' + req.getHeader('key'));
        System.debug('req.getHeader(\'address\') = ' + req.getHeader('address'));
        
        HttpResponse res = h.send(req);
        
        System.debug('res = ' + res);
        System.debug('res.getBody() = ' + res.getBody());

    }

And the logs im getting from my multitude of debug statements are:  (sorry for it being an image) 

User-added image
Hey,

Thought I had understood all this fine but cant get the challenge to pass. Im going slowl mad and have probably made a dumb error. 

What am I doing wrong, or is the challenge broken? Any help much appreciated. 
The error I get is
Challenge Not yet complete... here's what's wrong: 
The campingListItem JavaScript controller isn't setting the 'item' attribute correctly.
My component
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true" />
    <p>Name:
        <ui:outputText value="{!v.item.Name}"/>
    </p>
    <p>Price:
        <ui:outputCurrency value="{!v.item.Price__c}"/>
    </p>
    <p>Date:
        <ui:outputNumber value="{!v.item.Quantity__c}"/>
    </p>
    <p>Packed?:
        <ui:outputCheckbox value="{!v.item.Packed__c}"/>
    </p>
    <ui:button label="Packed!" press="{!c.packItem}" />
</aura:component>
My controller
({
	packItem : function(component, event, helper) {
        component.set("v.item.Packed__c", true);
        //console.log( JSON.stringify("v.item"));
        event.getSource().set("v.disabled" ,true);
	}
})









 
Hey all apologies, Im certain thius is something elementary but Ive been going round it for ages now and losing my tiny mind. 

Im working on a custom lightning componsnt and need to geocode adresses to put them on a map. I beleive Im correct in thinking that lightning wont let me call the geocoding WS directly from the JS and instead need to do this in apex. 

Issue Im having is I cant even get a dead simple request to googles geocode to work correctly, instead as below it returns me an error - Invalid request. Missing the 'address', 'bounds', 'components', 'latlng' or 'place_id' parameter ie not seeing the address param Im setting using req.setHeader('address', addrEncode  );. Via Postam or browser this works fine.

Apex Class
@AuraEnabled
    public static void testGeocodeWS() {
        
        System.debug('testGeocodeWS');
        String endpoint = 'https://maps.googleapis.com/maps/api/geocode/json';
        String addrRaw = 'SAPPHIRE HOUSE UNIT 2, CRISTAL BUSINESS CENTRE , 47 KNIGHTSDALE ROAD , IPSWICH , IP1 4JJ';
        String key = 'XXX OBSCURED FOR POST XXX';
        
        String addrEncode  = System.EncodingUtil.urlEncode(addrRaw, 'UTF-8' );
        
        System.debug('addrEncode = ' + addrEncode);
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint(endpoint);
        req.setMethod('GET');
        req.setHeader('address', addrEncode  );
        req.setHeader('key', key );
        
        System.debug('req = ' + req);
        System.debug('req.getEndpoint() = ' + req.getEndpoint());
        System.debug('req.getHeader(\'key\') = ' + req.getHeader('key'));
        System.debug('req.getHeader(\'address\') = ' + req.getHeader('address'));
        
        HttpResponse res = h.send(req);
        
        System.debug('res = ' + res);
        System.debug('res.getBody() = ' + res.getBody());

    }

And the logs im getting from my multitude of debug statements are:  (sorry for it being an image) 

User-added image
Hey,

Thought I had understood all this fine but cant get the challenge to pass. Im going slowl mad and have probably made a dumb error. 

What am I doing wrong, or is the challenge broken? Any help much appreciated. 
The error I get is
Challenge Not yet complete... here's what's wrong: 
The campingListItem JavaScript controller isn't setting the 'item' attribute correctly.
My component
<aura:component >
    <aura:attribute name="item" type="Camping_Item__c" required="true" />
    <p>Name:
        <ui:outputText value="{!v.item.Name}"/>
    </p>
    <p>Price:
        <ui:outputCurrency value="{!v.item.Price__c}"/>
    </p>
    <p>Date:
        <ui:outputNumber value="{!v.item.Quantity__c}"/>
    </p>
    <p>Packed?:
        <ui:outputCheckbox value="{!v.item.Packed__c}"/>
    </p>
    <ui:button label="Packed!" press="{!c.packItem}" />
</aura:component>
My controller
({
	packItem : function(component, event, helper) {
        component.set("v.item.Packed__c", true);
        //console.log( JSON.stringify("v.item"));
        event.getSource().set("v.disabled" ,true);
	}
})