javascript - Find polygon for place in KML -


note: please make sure read updates @ bottom!!


i have kml file load 'onto' google map; have searchbox users can search city. when city found place marker which, in (if not all) cases should fall in 1 of polygons defined in kml.

i can click polygon , shows info-popup areacode area; however: when marker placed have info-popup shown automatically (and possibly other(s) shown before placing marker hidden).

i have looked on maps v3 documentation unable find anything. possible?

you can view project @ http://netnummer.robiii.me, source can found @ https://github.com/robthree/netnummersnl

the relevant (snippet of) code is:

google.maps.event.addlistener(autocomplete, 'place_changed', function () {     var place = autocomplete.getplace();     if (!place.geometry)         return;      // remove existing markers     (var = 0, marker; marker = markers[i]; i++)         marker.setmap(null);     markers = [];      // create marker place.     var marker = new google.maps.marker({         map: map,         icon: image,         title: place.name,         position: place.geometry.location     });     markers.push(marker);      // ... here should figure out in polygon marker positioned     // ... , preferrably open/display info-window shown when     // ... polygon clicked.      // scroll (pan) marker     map.panto(place.geometry.location); }); 

also, side-question: autocomplete.getplace(); returns object; best way find out if object actual (useful) place? when search xxxx example, getplace() returns object {name: "xxxx"}, actual result (like searching amsterdam) returns object {address_components: array[4], adr_address: "<span class="locality">amsterdam</span>, <span class="country-name">nederland</span>", …}. use if (!place.geometry) find out if place useful / actual place; guess there's better way ('best practice'?) this?


edit 1: stumbled across with google maps api v3, determine if marker inside kml layer boundary. looking it. however, should note kml hosted 3rd party , updated @ them; use static site hosting prefer not have separate process extract coordinates polygons kml file. prefer "read" kml (in)directly.


edit 2: moved from (direct) kml a fusiontables based solution. can "highlight" polygons place in. (still) need way figure out how show it's infowindow. i'll tomorrow; seems need query (again) into datatable or something , label info way.


edit 3: solved!

i should've been in bed (see edits , comments) hey... don't let go easily...

so here's did:

  1. move (direct) kml fusion tables (resulting html)
  2. fire off query using google visualization's datatables data want specific region (resulting html)
  3. use place variable had lat/lng , name , show infowindow
  4. ...
  5. profit!

i purposely linked above links specific diffs or files of specific version later changes/updates won't mess answer. it's bit post specifics in post hope helps someone.

the final result can seen here.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -