开发者

Flex 4.5 navigateToURL maps.google.com using street address instead of lat and long

开发者 https://www.devze.com 2023-03-25 07:42 出处:网络
I have an application where the user will click a button and map an address on the native google map API.I can find lots of examples of how to do this with lat + long, but nothing about how to pass an

I have an application where the user will click a button and map an address on the native google map API. I can find lots of examples of how to do this with lat + long, but nothing about how to pass an address. I can do the following, where homeLoc.text is a latitude and longitude: navigateToURL(new URLRequest("http://maps.google.com/?q=" + homeLoc.text));

It is hard to believe this would be difficult, but I can not find any examples using a street address.

Anybody out there done something like this? Must be a p开发者_JAVA百科retty common use case.

Thanks,

Mark


Right. The problem with using an address directly is that it doesn't know how many possible outcomes there can be. It could be 1, or it can be millions.

Because of this, google insists that you use their Geocoding API to get a LatLong from an Address. If only one result is returned, you can handle opening google maps at the correct location, but if more than one (or none) is returned, you can handle it yourself in the app before continuing.


Alert.show("Open new tab to search in Google Maps?", "No places found", Alert.YES | 
Alert.NO, null, alertListener, null, Alert.NO);

    function alertListener(eventObj:CloseEvent):void {
     // Open Google in new tab.
     if (eventObj.detail==Alert.YES) 
     {
    var url:String = "http://maps.google.com.au/maps?q=" + onelineaddress.text; 
    var urlReq:URLRequest = new URLRequest(url);
navigateToURL(urlReq, "_blank");   
    }                        
    }

This works for me.

0

精彩评论

暂无评论...
验证码 换一张
取 消