Multiple Geocoding - Places and Markers

354 views
Skip to first unread message

Alex

unread,
Jun 6, 2011, 8:45:25 AM6/6/11
to Google Maps JavaScript API v3
Hello,

I'm looking for a solution using Geocoding.
I work on an asynchronous maps API (JS V3).

The first geocoder is used to center the map on a region selected by
the user (via multiple dropdown).
Here no problem it's running.
The second geocoding function I wanted to push have to push the
markers via a string request (brand stores here)
But it's not running well.. May have I made a mistake here.

Can you help me ? :)

geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': masterSelection },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " +
status);
}
});

geocoder2 = new google.maps.Geocoder();
var brandName = "Brand Name";
geocoder2.geocode( { 'address': brandName }, function(resultat, etat)
{
if (etat == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: resultat[0].geometry.location
});
} else {
alert("MARKER PROBLEM: " + etat);
}
});


Thanks !

geoco...@gmail.com

unread,
Jun 6, 2011, 5:28:12 PM6/6/11
to Google Maps JavaScript API v3
On Jun 6, 5:45 am, Alex <alex.was.pere...@gmail.com> wrote:
> Hello,
>
> I'm looking for a solution using Geocoding.

from the "articles" section of the documentation:
Geocoding Strategies
An overview of different strategies you can use for making sure
you stay within the Google Maps API geocoding limits. This is a good
article to read if you find you are frequently running into the quota
limits of the Maps API Geocoders.
http://code.google.com/apis/maps/articles/geocodestrat.html

> I work on an asynchronous maps API (JS V3).
>
> The first geocoder is used to center the map on a region selected by
> the user (via multiple dropdown).
> Here no problem it's running.
> The second geocoding function I wanted to push have to push the
> markers via a string request (brand stores here)
> But it's not running well..

What does that mean? What error are you getting?

Either provide complete information of read and follow the posting
guidelines:

http://groups.google.com/group/google-maps-js-api-v3/t/2b3f101fd509919e

(provide a link to your map, not code)

-- Larry

Alex

unread,
Jun 7, 2011, 11:11:55 AM6/7/11
to Google Maps JavaScript API v3
Hello Larry,

Thanks for your answer.
Sorry for the code in the email, please find below a test page.

http://proudly-geek.com/maptest/testapiplace.html

You'll see that I use asynchronous integration of the map (because in
real i'm using an asp.net framework to build my site), so please don't
mind about this.

The code changed since yesterday, i think i'm more on the right way.
I wanna mix the geocode function used to find a place (here : Paris
France, but it'll be generated dynamically by the user in the final
website) with the place marker function.

In the example above, i tried to match the "Nike" places (stores for
example) in Paris.
As you'll see, the map is matching the city well, but not the markers
on the places.

Thanks for your help,
Let me know if you've got any question.

Alex


On Jun 6, 11:28 pm, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> On Jun 6, 5:45 am, Alex <alex.was.pere...@gmail.com> wrote:
>
> > Hello,
>
> > I'm looking for a solution using Geocoding.
>
> from the "articles" section of the documentation:
> Geocoding Strategies
>     An overview of different strategies you can use for making sure
> you stay within the Google Maps API geocoding limits. This is a good
> article to read if you find you are frequently running into the quota
> limits of the Maps API Geocoders.http://code.google.com/apis/maps/articles/geocodestrat.html

Rossko

unread,
Jun 7, 2011, 1:23:41 PM6/7/11
to Google Maps JavaScript API v3
> I wanna mix the geocode function used to find a place (here : Paris
> France, but it'll be generated dynamically by the user in the final
> website) with the place marker function.

That's fine, that's what geocoding is for.

> In the example above, i tried to match the "Nike" places (stores for
> example) in Paris.

Have you looked at the script error?
locationArea is not defined

In your geocoding callback
geocoder.geocode( { 'address': "Paris France" }, function(results,
status) {
...
var locationArea = results[0] ...

the variable 'locationArea' is defined as local in scope to the
callback function. It is not accessible outside of the callback
function.

It is not available in this line of code in your main initialize()
function
var storeArea = new google.maps.LatLng(locationArea);
so it throws the error

If you want to use the results returned in a callback, use it within
the callback. Move your store-search code inside the geocoding
callback, so that it will be run when the geocode results are
available.

Alex

unread,
Jun 7, 2011, 4:00:18 PM6/7/11
to Google Maps JavaScript API v3
Hello Rossko,
Thanks for your answer.
I updated the code with changes you requested. Now all the script
looks running well, but still no marker on the map.

Maybe I made something wrong.
Let me know.

Thanks a lot !

Rossko

unread,
Jun 7, 2011, 5:49:13 PM6/7/11
to Google Maps JavaScript API v3
> I updated the code with changes you requested. Now all the script
> looks running well, but still no marker on the map.

In your new callback -
var locationArea = results[0].geometry.location.lat()+", "+results
you make a string, then
var storeArea = new google.maps.LatLng(locationArea);
LatLng expects to be given two numbers, not one string.

Have you considered using results[0].geometry.location directly as
this is already a LatLng ?
http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingResults

The next problem might be with trying to reference a function before
you have declared it (depending on your browser)
service.search(request, callback);
function callback(results, status) {

Alex

unread,
Jun 8, 2011, 5:58:32 AM6/8/11
to Google Maps JavaScript API v3
Yes, the problem came from the string.
Using the results[0].geometry.location object, it's working well
now :)

Thanks a lot for your help !!

Additionnal last question : do you know if there's any radius limit on
the place search ?

On Jun 7, 11:49 pm, Rossko <ros...@culzean.clara.co.uk> wrote:
> > I updated the code with changes you requested. Now all the script
> > looks running well, but still no marker on the map.
>
> In your new callback -
>    var locationArea = results[0].geometry.location.lat()+", "+results
> you make a string, then
>     var storeArea = new google.maps.LatLng(locationArea);
> LatLng expects to be given two numbers, not one string.
>
> Have you considered using results[0].geometry.location directly as
> this is already a LatLng ?http://code.google.com/apis/maps/documentation/javascript/services.ht...

Alex

unread,
Jun 8, 2011, 9:39:31 AM6/8/11
to Google Maps JavaScript API v3
Ultimate last question.
I want to display the full adress of each place in the infowindow.
I tried to use place.formatted_address object, but this one appear
undefined.

An idea to display it ?

google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name+" "+place.formatted_address);
infowindow.open(map, this);

en4ce

unread,
Jun 8, 2011, 11:00:14 AM6/8/11
to Google Maps JavaScript API v3
that happens here and there (my self just saw that on
formatted_phone_number), just do a check like

if (place.formatted_address==undefined){do what you want}

Alex

unread,
Jun 8, 2011, 6:11:28 PM6/8/11
to Google Maps JavaScript API v3
Yes, i know that.
But is there any solution to display in my infowindow the full
address ?
An object maybe ?

Thx

Alex

unread,
Jun 9, 2011, 4:44:47 AM6/9/11
to Google Maps JavaScript API v3
I updated my code at the same address.
http://proudly-geek.com/maptest/testapiplace.html

I'm still stuck with the same problem.
I've found that on the API V2, the function runs with localsearch
function, but not find similar objects in the Places V3 librairie.
No solution on V3 to have this formatted_address (or equivalent)
object at the place of place.name in my infowindow call ?

Thanks a lot by advance !

Rossko

unread,
Jun 9, 2011, 5:08:26 AM6/9/11
to Google Maps JavaScript API v3
> No solution on V3 to have this formatted_address (or equivalent)
> object at the place of place.name in my infowindow call ?

Of course, but you have to write code to do it.
Places results are described at
http://code.google.com/apis/maps/documentation/places/#PlaceSearchResults
have you looked at the 'vicinity' ?

The next section describes Place Details
http://code.google.com/apis/maps/documentation/places/#PlaceDetails
the methods used there apply to the HTTP service, not directly to the
PlacesService of the maps API, but the reference outlines how to
retrieve the details
http://code.google.com/apis/maps/documentation/javascript/reference.html#PlaceDetailsRequest
with getDetails()

It doesn't seem to be well documented yet.
> > > > > >     function callback(results, status) {- Hide quoted text -
>
> - Show quoted text -

Alex

unread,
Jun 10, 2011, 6:12:37 AM6/10/11
to Google Maps JavaScript API v3
Hi Rossko,

Thanks for the details, i'm beginning to reach the final line :) but
not yet.
Is it possible to use service.getDetails method in addition of my
service.search ?
I've tried it (my code), with no success for the moment.

service.getDetails seems to be use for a unique request, so i can't
use it for my whole first search (looking for store in a radius), have
I need to put it after the search method.
Looking on my code, i don't really know where to place the getDetails
method to apply it on all my markers places found.

Thx !

On Jun 9, 11:08 am, Rossko <ros...@culzean.clara.co.uk> wrote:
> > No solution on V3 to have this formatted_address (or equivalent)
> > object at the place of place.name in my infowindow call ?
>
> Of course, but you have to write code to do it.
> Places results are described athttp://code.google.com/apis/maps/documentation/places/#PlaceSearchRes...
> have you looked at the 'vicinity' ?
>
> The next section describes Place Detailshttp://code.google.com/apis/maps/documentation/places/#PlaceDetails
> the methods used there apply to the HTTP service, not directly to the
> PlacesService of the maps API, but the reference outlines how to
> retrieve the detailshttp://code.google.com/apis/maps/documentation/javascript/reference.h...

Rossko

unread,
Jun 10, 2011, 6:39:43 AM6/10/11
to Google Maps JavaScript API v3
> service.getDetails seems to be use for a unique request, so i can't
> use it for my whole first search (looking for store in a radius)

Yes, that is what the documentation says.

> have
> I need to put it after the search method.

Yes, because you need the unique key that comes in the search results.

> Looking on my code, i don't really know where to place the getDetails
> method to apply it on all my markers places found.

In your first search callback, for each result that you are interested
in, get its unique key and fire off a getDetails(). Each
getDetails() will need to be linked another own callback that process
the details results, presumably in your case populating the
infowindow.

David Terrazas

unread,
Jun 27, 2011, 11:20:17 AM6/27/11
to google-map...@googlegroups.com
I am having the same issues but I cannot seem to figure out the syntax. I can pass the reference id to the .getDetails() function, I get a status of "OK" but I cannot figure out the syntax to get the detailed information.  What Object is it returned in and what is the syntax to retrieve it?
Reply all
Reply to author
Forward
0 new messages